Home > Blockchain >  how use Scanner and push that values to an array in java?
how use Scanner and push that values to an array in java?

Time:10-13

I want to push values from a Scanner to an Array. I want to know if this code is right. How to do if it is wrong? This is a method I call over and over again. So I want to store that user input values in an Array.

    String[] student_id = new String[150];  
    String studentId = "";

    System.out.print("Enter Student ID   : ");
    studentId = input.nextLine();
   
    student_id = studentId;
   
    for(int i =0;i<student_id.length;i  ) {
       student_id[i] = input.nextLine();
    }

CodePudding user response:

easy

String[] student_id=new String[150];        
    System.out.print("Enter Student ID   : ");
    for(int i =0;i<student_id.length;i  ){
    student_id[i] = input.nextLine();
}
  • Related