2
Contributors
5
Replies
6
Views
8 Years
Discussion Span
Last Post by javaAddict
0
boolean stop = false;

while (!stop) {

//code to be repeated 


//ask user if he/she wants to stop
if yes stop = true;
}
0

This forum is full of examples on how to read input from the keyboard.
Do a little search.

Also check the classes:

Scanner
BufferedReader

-1

This forum is full of examples on how to read input from the keyboard.
Do a little search.

Also check the classes:

Scanner
BufferedReader

so would i do something like this:

Scanner keyboard = new Scanner(System.in);

System.out.println("Enter true to repeat game.");
boolean true = keyboard.next();

if this is right would i do this in the while loop or outside of it
thanks for your help

Comments
Still no code tags
0

so would i do something like this:

Scanner keyboard = new Scanner(System.in);

System.out.println("Enter true to repeat game.");
boolean true = keyboard.next();

if this is right would i do this in the while loop or outside of it
thanks for your help

I don't believe that this is correct: boolean true = keyboard.next(); because you can't give your variables names like: true which is a keyword for java.

I was thinking something like:

System.out.println("Enter N to stop game.");
String input = keyboard.next();

if (input.equals("N")) {
  stop = true;
}

But since you have marked the thread solved you probably have already figured it out

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.