I am trying to insert some value from user input in two dimensional String array i'm using two code to test that but both of them skipping the first column and store nothing. Here the code and the image of result.
First code:
Scanner sc= new Scanner(System.in);
System.out.print("Enter Number of Students ");
int a= sc.nextInt();
String [][] StudentDetail = new String[a][2];
System.out.println("Enter Details of "+ a+ " students");
for (int row = 0; row < StudentDetail.length; row++) {
System.out.print("Enter name: ");
StudentDetail[row][0] = sc.nextLine();
System.out.print("Enter a ID ");
StudentDetail[row][1] = sc.nextLine();
}
System.out.println( StudentDetail[0][0] );
System.out.println( StudentDetail[0][1] );
}
Second code :
for (int i=0; i<a; i++) {
System.out.println("Enter Details of student "+ (i+1));
for (int j=0;j<2;j++){
StudentDetail[i][j] = sc.nextLine();
}
}
The result of first code: