for(int i = 0; i < regArray.length; i++){
System.out.println("Registration number : " + Registration.getNextRegNo());
System.out.println("Enter name = ");
String name = sc.nextLine();
System.out.println("Enter IC name = ");
String IC = sc.next();
Owner owner = new Owner(name, IC);
System.out.println("Enter plate number = ");
String plateNo = sc.next();
System.out.println("Enter color = ");
String color = sc.next();
System.out.println("Enter year = ");
int year = sc.nextInt();
System.out.println("Enter car type = ");
for(int x = 0; x < carTypeArray.length; x++){
System.out.println(x + ": " + carTypeArray[x]);
}
int choice = sc.nextInt();
CarType carType = carTypeArray[choice];
Car car = new Car(plateNo, color, year, carType);
regArray[i] = new Registration(owner, car);
sc.nextLine();
}
Hi, JAVA newbie here. I have recently tried to create a registration program as shown by the code sample above. I came to realise that the final sc.nextLine() is used to absorb the enter input from user after they typed their car type. When I change it to sc.next(), the program seems to accept the first input i.e. 1 and when i press enter the program doesnt stop reading input. However, when i type in a second character and press enter again, the program seems to proceed and repeat the loop.