Java input mismatch error using scanner

前端 未结 3 1522
时光取名叫无心
时光取名叫无心 2021-01-26 19:28

I am a novice Java student and am trying to complete a program that uses the scanner to input 5 students\' names, and then a loop within to get 3 grades for each student. I am

3条回答
  •  Happy的楠姐
    2021-01-26 19:34

    Yes, like others have suggested, your problem in in the line:

    grades[studentNumber][courseNumber] = input.nextInt();
    

    Because your input is not recognised as an integer.

    You should also be aware that your code will not loop through five times, it will go through once and exit since if statements do not repeat.

    To loop you should probably use a for loop, something along these lines:

    for(int i = 0; i < 5; i++){
        //You code should be the same in here
    }
    

    Or change your if's to while.

提交回复
热议问题