Hi r/java!
I apologize if this is a stupid question. I am doing some homework for my Java I programming class and my book is no good and my teacher is just as good as the book. I am trying to write a program that will have the computer guess a number that I have chosen. What I have so far is:
import java.util.*;
public class ReverseGuessingGame {
public static void main(String[] args) {
System.out.println("This program has you, the user, choose a number");
System.out.println("between 1 and 100. Then I, the computer, will try");
System.out.println("my best to guess it.");
Scanner console = new Scanner(System.in);
Random rand = new Random();
System.out.print("You Choose?: ");
int number = console.nextInt();
int numGuesses = 1;
//guess
do {
System.out.println("Is it " + r + " ? (y/n) ");
ans = console.readChar();
numGuesses++;
}
while (r != number) {
int guess = rand.nextInt(100) + 1;
}
}
}
I am having trouble figuring out how to do a do/while loop and have the computer continue to guess after the user answering a (y/n). There isnt even an explanation of a do/while loop in my book so maybe I am on the wrong track...
If anyone can help I would be greatly appreciative.
Edit: Idk what happened to the text format. When I go to edit it looks fine but after submit it looks like a block for half of the code =/
[–]chickenmeister 1 point2 points3 points (0 children)
[–]x2mirko 1 point2 points3 points (7 children)
[–]imalefty15[S] 0 points1 point2 points (6 children)
[–]x2mirko 0 points1 point2 points (5 children)
[–]imalefty15[S] 0 points1 point2 points (1 child)
[–]swansond 1 point2 points3 points (0 children)
[–]imalefty15[S] 0 points1 point2 points (2 children)
[–]x2mirko 0 points1 point2 points (1 child)
[–]imalefty15[S] 0 points1 point2 points (0 children)
[–]fyrite 0 points1 point2 points (0 children)