Why is first for loop iteration skipped?

后端 未结 5 2205
粉色の甜心
粉色の甜心 2021-01-26 10:57

my code is yielding an unexpected result. It seems my for loop skips the first iteration and I don\'t understand why.

public static void main(String[] args) {

         


        
5条回答
  •  自闭症患者
    2021-01-26 11:15

    What worked for me was instantiating a new Scanner in each iteration:

    for(int i = 0; i < number; i++)
    {
        System.out.println("Enter family member name: ");
    
        Scanner loopGet = new Scanner(System.in);
        family_name = loopGet.nextLine();
        family_array[i] = family_name;
    }
    

提交回复
热议问题