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 3 of 3

Thread: Nested Statements problem

  1. #1
    Junior Member
    Join Date
    Aug 2017
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Nested Statements problem

    Hello, I'm new to Java and working on a Nested Statements section of a beginner's Java course. Please help me identify the problem in my code as I have been through it multiple times and can't figure it out. Thanks in advance.

    The error message is: FinishLine.java:63: error: reached end of file while parsing } ^ 1 error

    This is my code

    import java.util.Scanner;
    /****************
     * Alex
     * FinishLine.java
     * 04/09/2023
     * *************/
    public class FinishLine {
     
      public static void main(String[] args) {
        //Variables
        int speed = 0;
        int min = 0;
        int max = 10;
     
        //Scanner
        Scanner input = new Scanner(System.in);
     
        //Ask for user input
        System.out.println("Enter an integer between 0 and 10 for the speed of the car!");
     
        //Read in input
     
        //Random number
        int pressure = ((int) (Math.random() * ((max - min) + 1))) + min;
    	pressure = 1;
        /****************************************************
    	 * Compare speed to engine pressure which is a random number
    	 * if speed is equal to pressure then print out "Game over!"
    	 * else if speed is NOT equal to the pressure ask for new number
    	 * If the speed isn't equal to the pressure 3 times then Derrik crosses the finish line.
    	 ****************************************************/
        if(speed == pressure) {
          System.out.println("Game Over!");
          System.out.println("Engine pressure " + pressure);
        }
        else if(speed != pressure) {
          //Ask for user input for 2nd time
          System.out.println("Almost there, enter another integer between 0 and 10 for the speed of the car!");
     
          //Read in input for 2nd time
     
     
          if(speed == pressure) {
            System.out.println("Game Over!");
            System.out.println("Engine pressure " + pressure);
          }
          else {
            //Ask for user input for 3rd time
            System.out.println("Get across that finish line! Enter an integer between 0 and 10 for the speed of the car!");
     
            speed = input.nextInt();
            System.out.println("Speed " + speed);
            pressure = 0;
     
            //add nested if statement below
            if(speed == pressure) {
            System.out.println("Game Over");
            System.out.println("Engine pressure " + pressure);
            }
          else {
            System.out.println("Congrats! Derrick made it across the finsh line!");
            System.out.println("Engine pressure " + pressure);
          }
    Last edited by krieger71; August 1st, 2017 at 11:02 AM.

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Nested Statements problem

    error: reached end of file while parsing }
    Are the { and }s properly matched? Check that there is one } for every {

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.

    See: https://coderanch.com/t/682844/java/...-error#3204069
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Aug 2017
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Nested Statements problem

    Thank you. I'll check and I edited it as suggested. Thanks!

Similar Threads

  1. [SOLVED] Nested 'If' Statements
    By Cal S. in forum What's Wrong With My Code?
    Replies: 9
    Last Post: September 12th, 2014, 08:41 AM
  2. Having some nested loop problem
    By joel1314 in forum Loops & Control Statements
    Replies: 13
    Last Post: June 3rd, 2012, 05:04 AM
  3. Problem with if statements
    By Omnamah in forum Loops & Control Statements
    Replies: 4
    Last Post: September 4th, 2011, 11:13 AM
  4. [SOLVED] Help with nested if statements.
    By joon in forum What's Wrong With My Code?
    Replies: 8
    Last Post: June 17th, 2011, 10:25 AM
  5. Nested-If Problem/ Initializing
    By ak120691 in forum What's Wrong With My Code?
    Replies: 6
    Last Post: March 2nd, 2011, 08:37 PM

Tags for this Thread