This is a silly game written in Python, I was wondering how to reproduce it in Java:
name = ''
while name != 'your name':
print('Please type your name.')
name = input()
print('Thank you!')
Basically, it requests to write the string "your name" to break the while loop, now, I've tried this code in Java but it throws an error:
import java.util.Scanner;
public class sillyGame {
public static void main(String [] args) {
String name = "";
while (name != "your name"){
System.out.println("Please type your name");
Scanner input = new Scanner(System.in);
name = input.next();
input.close();
}
System.out.println("thank you");
}
}
The error is: "Exception in thread "main" java.util.NoSuchElementException"
I really appreciate your help.