Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 12 of 12

Thread: Re: }while(guess1!=gen1) ';' expected Compiler error

  1. #1
    Junior Member
    Join Date
    Oct 2013
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: }while(guess1!=gen1) ';' expected Compiler error

    My program keeps throwing this compiler error and my program is due by 12. Cannot figure this out. Please help.


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

    //Michael Morris CSC151

    public class PP4_8
    {
    public static void main (String [] args)
    {
    Random generator=new Random();
    Scanner scan=new Scanner(System.in);

    final int MAX=100;
    int gen1;
    int guess1;
    int sum;

    gen1=generator.nextInt(MAX)+ 0;


    while (another.equalsIgnoreCase("y"))
    {
    while(guess1!=0)
    {
    do
    {

    System.out.println("I'm thinking of a number betweeen 1 and Max" +MAX +"can you guess what it is:");
    guess1=scan.nextInt();

    sum=guess1;
    if(guess1==gen1)
    System.out.println("The guess is correct");
    if(guess1<gen1)
    System.out.println("The guess is too low");
    if(guess1>gen1)
    System.out.println("The guess is too high");

    System.out.println("The sum of guesses are:" +sum);

    }while(guess1!=gen1)

    System.out.println("Do you want too play again enter y for yes");
    another=scan.nextLine();
    }
    }
    }

    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: }while(guess1!=gen1) ';' expected Compiler error

    compiler error
    Please copy the full text of the error message and paste it here. It has important info about the error.

    Please edit your post and wrap your code with code tags:
    [code=java]
    YOUR CODE GOES HERE
    [/code]
    to get highlighting and preserve formatting.

    Make sure the indentations are done properly for nested statements.

    What happens when you add a ; where the compiler wants one?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Oct 2013
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: }while(guess1!=gen1) ';' expected Compiler error

    }while(guess1!=gen1) ';' expected- this is the error message

    If I add a semicolon ; at that while(guess1!=gen1) then I get another compiler error message of can't find the symbol at this while
    statement while (another.equalsIgnoreCase("y"))

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: }while(guess1!=gen1) ';' expected Compiler error

    get another compiler error
    Please copy the full text of the error message and paste it here. It has important info about the error.

    Please edit your post and wrap your code with code tags:
    [code=java]
    YOUR CODE GOES HERE
    [/code]
    to get highlighting and preserve formatting.

    Make sure the indentations are done properly for nested statements.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Oct 2013
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: }while(guess1!=gen1) ';' expected Compiler error

     import java.util.Scanner;
    import java.util.Random;
     
    //Michael Morris CSC151
     
    public class PP4_8
    {
      public static void main (String [] args)
    {
    Random generator=new Random();
    Scanner scan=new Scanner(System.in);
     
    final int MAX=100;
    int gen1;
    int guess1;
    int sum;
     
    gen1=generator.nextInt(MAX)+ 0;
     
     
       while (another.equalsIgnoreCase("y"))
    {
        while(guess1!=0)
     {
       do
    {
     
    System.out.println("I'm thinking of a number betweeen 1 and Max" +MAX +"can you guess what it is:");
                        guess1=scan.nextInt();
     
    sum=guess1;                    
       if(guess1==gen1)
       System.out.println("The guess is correct");
     
       if(guess1<gen1)
       System.out.println("The guess is too low");
       if(guess1>gen1)
       System.out.println("The guess is too high");
     
    System.out.println("The sum of guesses are:" +sum);   
     
    }while(guess1!=gen1);
     
    System.out.println("Do you want too play again enter y for yes");
    another=scan.nextLine();
    }
    }
     
        }
    }

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: }while(guess1!=gen1) ';' expected Compiler error

    The formatting is all messed up. The nested statements aren't properly indented. Only one } should be in the first column. The other }s need to be in column beneath the start of the statements with the pairing {.
    It's almost impossible to read and understand the code as it is now formatted.

    Please copy the full text of the error message and paste it here. It has important info about the error.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Oct 2013
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: }while(guess1!=gen1) ';' expected Compiler error

     import java.util.Scanner;
     import java.util.Random;
     
     //Michael Morris CSC151
     
     public class PP4_8
        {
     public static void main (String [] args)
     {
     Random generator=new Random();
     Scanner scan=new Scanner(System.in);
     
    PP4_8.java:41: error: ';' expected
    while(guess1!=gen1)
                       ^
    1 error
    This is the complete error message[/B]
     
     
    [/U] final int MAX=100;
     int gen1;
     int guess1;
     int sum;
     
     gen1=generator.nextInt(MAX)+ 0;
     
     
          while (another.equalsIgnoreCase("y"))
          {
          while(guess1!=0)
          {
          do
          {
     
     System.out.println("I'm thinking of a number betweeen 1 and Max" +MAX +"can you guess what it is:");
     guess1=scan.nextInt();
     
     sum=guess1; 
     if(guess1==gen1)
     System.out.println("The guess is correct");
     if(guess1<gen1)
     System.out.println("The guess is too low");
     if(guess1>gen1)
     System.out.println("The guess is too high");
     
     System.out.println("The sum of guesses are:" +sum); 
            }
           while(guess1!=gen1)
     
     System.out.println("Do you want too play again enter y for yes");
     another=scan.nextLine();
              }
              }
              } 
     
              }


    --- Update ---

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

    //Michael Morris CSC151

    public class PP4_8
    {
    public static void main (String [] args)
    {
    Random generator=new Random();
    Scanner scan=new Scanner(System.in);

    PP4_8.java:41: error: ';' expected
    while(guess1!=gen1)
    ^




    final int MAX=100;
    int gen1;
    int guess1;
    int sum;

    gen1=generator.nextInt(MAX)+ 0;


    while (another.equalsIgnoreCase("y"))
    {
    while(guess1!=0)
    {
    do
    {

    System.out.println("I'm thinking of a number betweeen 1 and Max" +MAX +"can you guess what it is:");
    guess1=scan.nextInt();

    sum=guess1;
    if(guess1==gen1)
    System.out.println("The guess is correct");
    if(guess1<gen1)
    System.out.println("The guess is too low");
    if(guess1>gen1)
    System.out.println("The guess is too high");

    System.out.println("The sum of guesses are:" +sum);
    }
    while(guess1!=gen1)

    System.out.println("Do you want too play again enter y for yes");
    another=scan.nextLine();
    }
    }
    }

    }


    PP4_8.java:41: error: ';' expected
    while(guess1!=gen1)
    ^
    This is the complete error messsge

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: }while(guess1!=gen1) ';' expected Compiler error

    Is that the same error? Add a ; where the compiler says to.
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Junior Member
    Join Date
    Oct 2013
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: }while(guess1!=gen1) ';' expected Compiler error

    I did that and got another compiler error message of can't find the symbol at the while
    statement "while (another.equalsIgnoreCase("y"))". Never heard of a semicolon on a while statement.

  10. #10
    Member
    Join Date
    Aug 2013
    Posts
    95
    Thanks
    3
    Thanked 14 Times in 14 Posts

    Default Re: }while(guess1!=gen1) ';' expected Compiler error

    Why don't you post your full code. What is "another"?

  11. #11
    Junior Member
    Join Date
    Oct 2013
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: }while(guess1!=gen1) ';' expected Compiler error

    that was my full code and another is a string variable too hold one of my inputs at the end of my program.

  12. #12
    Member
    Join Date
    Aug 2013
    Posts
    95
    Thanks
    3
    Thanked 14 Times in 14 Posts

    Default Re: }while(guess1!=gen1) ';' expected Compiler error

    You aren't giving another any value are you? You are putting it in the while loop as a condition before giving it a value//

Similar Threads

  1. Replies: 2
    Last Post: March 23rd, 2014, 08:44 AM
  2. compiler error regarding method call
    By dan1967 in forum What's Wrong With My Code?
    Replies: 10
    Last Post: December 18th, 2011, 01:42 PM
  3. un-expected error
    By arvindbis in forum What's Wrong With My Code?
    Replies: 0
    Last Post: October 21st, 2011, 09:02 AM
  4. Map compiler error
    By kc120us in forum Collections and Generics
    Replies: 4
    Last Post: September 21st, 2011, 10:53 PM
  5. Java 6.0 Compiler Error
    By jilomes in forum What's Wrong With My Code?
    Replies: 2
    Last Post: April 19th, 2011, 04:34 PM