Why is first for loop iteration skipped?

后端 未结 5 2164
粉色の甜心
粉色の甜心 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:10

        number = get.nextInt();
         // if i enter 4 then it will 4\n and nextInt will take only 4 
         // and the \n will be taken as input by the getline.
        get.nextLine();  
         //this will return the "" from ""\n . so adding this will solve your problem
        family_array = new String[number];
    

提交回复
热议问题