Results 1 to 2 of 2
  1. #1
    emm139 is offline Member
    Join Date
    Sep 2013
    Posts
    1
    Rep Power
    0

    Default else without if error

    I am very new to java and I am having issues figuring out what is wrong with my code. I am doing methods and one section of my methods keeps showing a else without if error message. Please help!

    private static boolean isPerfect( int number )
    {
    int temp = 0;
    for(int i; i<=number/2; i++);
    if(number%i == 0)
    temp +=i;
    {
    if( temp == number)
    return true; // JUST TO MAKE IT COMPILE YOU MODIFY AS NEEDEDS
    }
    else;
    return false;
    }

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,767
    Rep Power
    5

    Default Re: else without if error

    First, please read the FAQ and guide for new members. Above all, put your code between [code][/code]tags.

    As far as your program goes, look at the first for statement. It is terminated by a semicolon. Also, for all of you if statements, make certain you use {} properly. Eve if the if statement only has a single consequence, always use {} to reduce ambiguity.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. Replies: 8
    Last Post: 11-22-2012, 07:16 AM
  2. Replies: 3
    Last Post: 05-08-2012, 05:26 PM
  3. Replies: 1
    Last Post: 12-05-2009, 07:28 AM
  4. Replies: 3
    Last Post: 01-23-2009, 08:53 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •