I'm getting an illgal start of expression error in my code for the public static boolean portion at the bottom... any ideas?

I'm getting an illgal start of expression error in my code for the public static boolean portion at the bottom... any ideas?

heres my code

import java.util.Scanner;
import java.util.Random;
public class numberGame {
    public static void main (String[] args) {
        Random rand = new Random ();
        Scanner keyboard = new Scanner(System.in); //User input
        int x = (int)(100 * Math.random()) + 1; //Generates random number
        int userInt = 0; //user input number
        char userAns;
        int counter = 0;
        boolean guess = true;
        System.out.print("The Number guessing game, Would you like to play?: ");
        String userAns1 = keyboard.nextLine();
        userAns = userAns1.charAt(0); 
        while (guess == true)
        {
            char userAns2 = 'y'; //Compare to Yes or No answer from user
            if (userAns != userAns2)
            {
                System.out.println("Goodbye!");
                guess = false;
                }
                else
                {
                    System.out.println("\nI am thinking of a number between 1 and 100. Try to guess it.\n");
        {
            System.out.println("\nI am thinking of a number between 1 and 100. Try to guess it.\n ");
            while (x != userInt)
            {
                System.out.print("Enter Number ");
                userInt = keyboard.nextInt();
                if (x < userInt)
                {
                    System.out.println(userInt + " Way too high, guess again ");
                    }
                    else if (x > userInt)
                    {
                        System.out.println(userInt + " too small, keep trying ");
                        }
                        else if (x = userInt)
                        {
                            System.out.println(userInt + " Right on the money, DING DING DING!!! ");
                        }
                        counter = counter + 1;                                                  
                        }
                        if (counter <= 3)
                        {
                            System.out.println("You've got it in " + counter + " Great work! You are a mathematical wizard!");
                            break;
                            }
                            else if (counter >= 3 && counter <= 7)
                                {
                                    System.out.println("You've got it in " + counter + "guesses, Not too bad! You've got some potential.");
                                    break;
                                    }
                                    else if (counter > 7)
                                    {
                                        System.out.println("You've got it in " + counter + " guesses. What took you so long? Maybe you should take some lessons");
                                        break;
                                        }
                                        {

public static boolean playAgain(){        
                        String answer;        
                        Scanner keyboard = new Scanner(System.in);
                        System.out.println("would you like to play again? ");        
                        answer = keyboard.nextLine();        
                        if (answer =="y");        
                        return true;    }
                        else   
                        return false;
                    }}}}}}
View Answers

July 3, 2012 at 11:09 AM

Here is a code of number game. We have modified it.

import java.util.Scanner;
import java.util.Random;
public class numberGame {
    public static void main (String[] args) {
        Random rand = new Random (); 
        Scanner keyboard = new Scanner(System.in);
        int x = (int)(100 * Math.random()) + 1;
        int userInt = 0;
        char userAns;
        int counter = 0;
        boolean guess = true;
        System.out.print("The Number guessing game, Would you like to play?: ");
        String userAns1 = keyboard.nextLine(); 
        userAns = userAns1.charAt(0);
        while (guess == true) {
            char userAns2 = 'y';
            if (userAns != userAns2) { 
                System.out.println("Goodbye!");
                guess = false;
            }
            else {
                System.out.println("\nI am thinking of a number between 1 and 100. Try to guess it.\n");

                while (x != userInt) { 
                    System.out.print("Enter Number ");
                    userInt = keyboard.nextInt();
                    if (x < userInt) { 
                        System.out.println(userInt + " Way too high, guess again ");
                    }
                    else if (x > userInt) {
                        System.out.println(userInt + " too small, keep trying "); 
                    }
                    else if (x == userInt) { 
                        System.out.println(userInt + " Right on the money, DING DING DING!!! ");
                    } counter = counter + 1;
                    } 
                    if (counter <= 3) { 
                        System.out.println("You've got it in " + counter + " Great work! You are a mathematical wizard!");
                        break;
                    }
                    else if (counter >= 3 && counter <= 7) { 
                        System.out.println("You've got it in " + counter + "guesses, Not too bad! You've got some potential.");
                        break; 
                    }
                    else if (counter > 7) {
                        System.out.println("You've got it in " + counter + " guesses. What took you so long? Maybe you should take some lessons");
                        break;
                    }
            }
        }
    }
                   public static boolean playAgain(){
                   String answer;
                   Scanner keyboard = new Scanner(System.in); System.out.println("would you like to play again? ");
                   answer = keyboard.nextLine();
                   if (answer =="y"){
                    return true; 
                    } 
                   else{
                    return false; 
                   }
                   }
                   }

Ads









Related Tutorials/Questions & Answers:
I'm getting an illgal start of expression error in my code for the public static boolean portion at the bottom... any ideas?
illegal start of expression in servlet error..
Advertisements
why i'm getting this error?The import javax.servlet.http cannot be resolved
i got illegal start of expression error , plese tell me the mistake where i did...
getting error in your login form code
i am unable to identify the error in my code
i am unable to identify the error in my code
error : not an sql expression statement
Getting an error :(
public static void main
Java - Boolean Expression and Operation in Java
Static keyword in public static void main
Applet run with appletviewer but not in browser, any code problem.
java code for print true if even and false if odd and print error if any float value with out using conditional and looping statement
Swing error in code
Code error
My Base Class is Changing every time in my code. How I can overcome this?
getting an error when set classpath
What happen when we write static public void instead of public static void?
ModuleNotFoundError: No module named 'portion'
Understanding public static void main function
data type used to store name.(getting an error)
getting following error org.hibernate.AnnotationException: No identifier specified for entity: inheritance_tutorial17.TwoWheeler
What is Public static void main
Solve my code
Conversion from String to boolean
ModuleNotFoundError: No module named 'static-code-checker'
changing final Boolean value in SwingUtilities.invokeLater()
ModuleNotFoundError: No module named 'bottom'
getting error while inserting values in database
I GOT ERROR FOR MY PROJECT

Ads