public static void main(String[] args) { Student[] test = new Student[7]; for (int i = 0; i < 7; i++) { test[i] = new Student(); Scanner kb = new Scanner(System.in); System.out.println("What is the Students ID number?: "); test[i].setStudentId(kb.nextInt()); System.out.println("What is the Students name?: "); test[i].setStudentName(kb.nextLine()); } } In the above program when I try to take integer input at first it skips the String input, but in the same program if i keep the string input at first it works fine. What might be the reason behind this?
Scanner kb = new Scanner(System.in); System.out.println("What is the Students name?: "); test[i].setStudentName(kb.nextLine()); System.out.println("What is the Students ID number?: "); test[i].setStudentId(kb.nextInt()); the output of the program would be
What is the Students ID number?: 1
What is the Students name?: //it wouldn't let me enter string here
What is the Students ID number?:
But when I take input for Integer above the string It works fine. What might be the reason?