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

12th Sep 2019, 10:28 PM
Jacques Cozart
Jacques Cozart - avatar
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!!"); } }
12th Sep 2019, 11:10 PM
blACk sh4d0w
blACk sh4d0w - avatar
+ 1
if you compare two strings you can't use ==. You have to use equals(). if(insTr.equals(courses[i][2]){ //print message }
12th Sep 2019, 11:28 PM
Denise Roßberg
Denise Roßberg - avatar
0
thx!!!
13th Sep 2019, 11:47 AM
Jacques Cozart
Jacques Cozart - avatar