Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Else and If statements "THANKS IN ADVANCE"-

807600Oct 25 2007 — edited Oct 25 2007
First off, I have a compiling error that reads " 'else' without 'if'. " I don't really understand what it's trying to tell me. Here's my program:
public class NumberSorter
{
    public NumberSorter()
    {
     //No body necessarry   
    }    

    public static void SortIt(double x, double y, double z)
    {
        if(x < y && x < z)
        {
            if(y < z)
            {
                System.out.println(x);
                System.out.println(y);
                System.out.println(z);
            }

            else
            {
                System.out.println(x);
                System.out.println(z);
                System.out.println(y);
            }
            
        else if(y < x && y < z)
        {
            if(x < z)
            {
                System.out.println(y);
                System.out.println(x);
                System.out.println(z);
            }
            
            else
            {
                System.out.println(y);
                System.out.println(z);
                System.out.println(x);
            }
        }   
        else if(z < x && z < y)
        {
            if (x < y)
            {
                System.out.println(z);
                System.out.println(x);
                System.out.println(y);
            }
            
            else
            {
                System.out.println(z);
                System.out.println(y);
                System.out.println(x);
            }
        }
    }
}
If you can't tell already, I'm trying to implement a class in which it can sort three numbers from least to greatest. The editor just keeps telling me that there's a problem with my "else if" part. As I've said before, I don't really understand this, and I would deeply appreciate if you can help me out. Oh yeah I probably won't get a chance to thank each one of you individually for helping me out, so I just want to say "THANK YOU SO MUCH"- for at least trying an attempt to help me.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 22 2007
Added on Oct 25 2007
4 comments
115 views