0
Searching an Array
Can i get some help plz...I preloaded the 5x3 array w/crs, day, instructor. When the peogram runs i get the correct crs info back, just a crs name then incalid instructor repeatedly??..... https://code.sololearn.com/c1U7FZbvg73Z/?ref=app
3 Answers
+ 2
Scanner input = new Scanner(System.in);
int i = 0;
System.out.println("Enter instructor name to search \n(Johnson / Brown/ Jones / Green / Hall)");
insrTr = input.nextLine();
boolean ifFound = false;
for(i = 0; i < 5; ++i)
{
if(insrTr.compareTo(courses[i][2]) == 0) {
ifFound = true;
break;
}
}
if(ifFound)
for(String s : courses[i])
System.out.println(s);
else System.out.println("Invalid Instructor Name!!");
}
}
+ 1
if you compare two strings you can't use ==. You have to use equals().
if(insTr.equals(courses[i][2]){
//print message
}
0
thx!!!