java - Why is my for only working on the first variable? -
the code wrote works fine if type in cosc 1337 once type of other elements in array display error message instead of time , date
what doing wrong?
import java.util.scanner; public class schedule { public static void main(string[] args) { string[][] arr = new string[4][2]; arr[0][0] = "cosc 1337"; arr[1][0] = "hist 1301"; arr[2][0] = "math 1302"; arr[3][0] = "phil 1320"; arr[0][1] = "wednesdays 12pm-3pm"; arr[1][1] = "fridays 8am-11am"; arr[2][1] = "mondays 6pm-9pm"; arr[3][1] = "saturdays 10am-1pm"; scanner in = new scanner(system.in); system.out.println("enter course"); string userinput = in.nextline(); (int = 0; < 4; i++) { if (userinput.equalsignorecase(arr[i][0])) { system.out.println("classes on: " + arr[i][1]); return; } if (!userinput.equalsignorecase(arr[i][0])) { system.out.println("invalid course"); return; } } } }
you never more first iteration in loop. invalid course statement should outside for-loop , called if 4 course checks fail
Comments
Post a Comment