I am having a problem with my program and I need some help. Anything would be greatly appreciated. I am running a guessing game.

Syntax error, insert "while ( Expression ) ;" to complete DoStatement
Syntax error, insert "}" to complete MethodBody

Here is my code:

import java.util.Scanner;
import java.util.Random;

public class Driver
{
public static void main(String[] args)
{
int z;
Double answer;
Double y;
Double n;
Scanner stdIn;
Random rand = new Random();
int x = rand.nextInt(100)+1;
do
{
System.out.println("Please guess a random number;");
z = stdIn.nextInt();
while(z != x)
{
if(z>x)
{
System.out.println("Too High. Guess Again:");
z = stdIn.nextInt();
}
else if(z<x)
{
System.out.println("Too Low. Guess Again:");
z = stdIn.nextInt();
{
System.out.println("Thats Correct!! Play again y or n?");
answer = stdIn.nextDouble();

}

}while(answer == y);

System.out.println("Thanks for playing!");
}

}

You have a brackets issue:

do
{
System.out.println("Please guess a random number;");
z = stdIn.nextInt();
while(z != x)
{
    if(z>x)
    {
        System.out.println("Too High. Guess Again:");
        z = stdIn.nextInt();
    }
    else if(z<x)
    {
         System.out.println("Too Low. Guess Again:");
         z = stdIn.nextInt();
    {                                              // change to '}' to end "else if" code

    //  add bracket '}' here to end inner while loop

    System.out.println("Thats Correct!! Play again y or n?");
    answer = stdIn.nextDouble();

}   //  delete this bracket

}while(answer == y);

See comments that I added on the brackets.

That's if I am understanding the program correctly. You're probably going to get a bunch of "might not be initialized" errors too. Also, are you sure you want "answer" and "y" to be doubles or should they be characters. I've never used "Scanner" so I'm of no help there. Is z what the user types in for a guess? x is the number the computer is thinking of?

This article has been dead for over six months. Start a new discussion instead.