In Java, I have tried
try (Scanner sc = new Scanner(System.in)) {
while (sc.hasNextLine()) {
System.out.print("Name: ");
String name = sc.nextLine();
System.out.println("Name is \"" + name + "\"");
}
}
but it doesn't output Name:
before asking for the input.
The console just shows an empty console window in which I can input the name.
How can I make sure Name:
is outputted before asking for the name?
Edit
try (Scanner sc = new Scanner(System.in)) {
System.out.print("Name: ");
while (sc.hasNextLine()) {
String name = sc.nextLine();
System.out.println("Name is \"" + name + "\"");
System.out.print("Age: ");
int age = sc.nextInt();
System.out.println("Age is " + age);
System.out.print("Name: ");
}