Question: Cant figure out whats wrong with this very simple code? public class worker { public static void main(String[] args){ //read in the file into string

Cant figure out whats wrong with this very simple code?

public class worker {

public static void main(String[] args){

//read in the file into string array of words

String[] commands = {"a","b","c"};

for(int i = 0; i<= commands.length; i++){

if (commands[i] == "a") {

System.out.print(commands[i]);

}

else if (commands[i] == "b") {

System.out.print(commands[i]);

}

else if (commands[i] == "c") {

System.out.print(commands[i]);

}

else{

System.out.print("none of these was found!");

}

}

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!