Scanner sc4 = new Scanner(System.in);
System.out.println("\nEnter the ID of the student you want to update!: ");
int id = sc4.nextInt();
System.out.println("Print1!");
String name = sc4.nextLine();
System.out.println("Print2!");
String address = sc4.nextLine();
System.out.println("Enter the updated contact Number of the student: ");
String contact = sc4.nextLine();
System.out.println("Enter the updated CourseID of the student: ");
int courseId = sc4.nextInt();
studentService.updateStudentById(id, name, address, contact, courseId);
break;
This code prints "Enter the ID of.." once and after receiving input from me, it prints both Print1 and Print2. Why does this happen?
Using scanner before every print statement solves this problem but I want a good programming approach towards this.