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: if else issues

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

    Default if else issues

    im getting a syntax error with my else statement. its not recognizing that i have an if statement preceding if. any suggestions???


  2. #2
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: if else issues

    Sure, post your code and the exact error message. We don't read minds.
    Improving the world one idiot at a time!

  3. #3
    Member GoodbyeWorld's Avatar
    Join Date
    Jul 2012
    Location
    Hidden command post deep within the bowels of a hidden bunker somewhere under a nondescrip building
    Posts
    161
    My Mood
    Stressed
    Thanks
    14
    Thanked 25 Times in 25 Posts

    Default Re: if else issues

    Are you by any chance getting a message saying

    "else without an if" or something like that?

    You might wanna check your brackets.

    For instance, this would be an issue that might cause an else to not be seen.

    if (variable == 5)
    System.out.println("Ut oh");
    System.out.println("Aw man");

    else
    System.out.println("What happened?");


    doing this will fix that problem:

    if (variable == 5)
    {
    System.out.println("Ut oh");
    System.out.println("Aw man");

    }

    else
    System.out.println("What happened?");

    The previous one only had the first statement go with the if. The second one was extra and hence caused it to mess up the if and else structure as the it acted like an intermediary statement, hence making it an else without an if.

    I can't be more specific as you don't have any code posted.

Similar Threads

  1. Issues with tree
    By IHeartProgramming in forum What's Wrong With My Code?
    Replies: 2
    Last Post: December 1st, 2012, 12:35 AM
  2. Issues with my ordering program - if statement issues?
    By Shenaniganizer in forum What's Wrong With My Code?
    Replies: 5
    Last Post: October 31st, 2012, 10:17 PM
  3. Jlabel issues
    By Wadashe in forum Java Theory & Questions
    Replies: 2
    Last Post: February 27th, 2012, 02:39 PM
  4. [SOLVED] Having Issues Wish this Program
    By userct in forum What's Wrong With My Code?
    Replies: 17
    Last Post: February 9th, 2012, 03:46 PM
  5. [SOLVED] Image issues
    By Toll in forum Java Theory & Questions
    Replies: 7
    Last Post: May 19th, 2011, 09:43 PM