I want to break loop when I send nothing to input. But when I type something to input at nameS
second time loop break by itself although the input wasn't empty.
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while(true) {
System.out.print("Name: ");
String nameS = sc.nextLine();
if(nameS.isEmpty()) {
break;
}
System.out.print("Student number: ");
int numberS = sc.nextInt();
}
}