Else if statements


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: Else if statements

  1. #1
    Join Date
    Dec 2004
    Posts
    46

    Else if statements

    Hi,

    Can someone tell me whats wrong with this statement:

    if (area1 > area2)
    {
    System.out.println("Area of Oblong 1 is Greater than Oblong 2");
    }
    else if
    {

    System.out.println("Area of Oblong 2 is Greater than Oblong 1");


    }


    else (area1 == area2)
    {
    System.out.println("Areas are the same");
    }

    Thanks

  2. #2
    Join Date
    Oct 2004
    Location
    Chicago
    Posts
    108
    if (area1 > area2)
    {
    System.out.println("Area of Oblong 1 is Greater than Oblong 2");
    }
    else if <<<<<<<<<<<<<<<<<< ERROR
    {

    System.out.println("Area of Oblong 2 is Greater than Oblong 1");


    }


    else (area1 == area2)
    {
    System.out.println("Areas are the same");
    }

    you need a condition for the second if statement

  3. #3
    Join Date
    Dec 2004
    Posts
    46
    Can i do it like this:

    Code:
    if (area1 > area2)
            {
                System.out.println("Area of Oblong 1 is Greater than Oblong 2");
            }
            else if (area2 > area1)
            {
                System.out.println("Area of Oblong 2 is Greater than Oblong 1");
            }
            else (area1 == area2)
            {
                System.out.println("Areas are the same");
            }
    Or is this incorrect?

  4. #4
    Join Date
    Oct 2004
    Location
    Chicago
    Posts
    108
    That is almost correct


    Code:
    if (area1 > area2)
            {
                System.out.println("Area of Oblong 1 is Greater than Oblong 2");
            }
            else if (area2 > area1)
            {
                System.out.println("Area of Oblong 2 is Greater than Oblong 1");
            }
            else if(area1 == area2)
            {
                System.out.println("Areas are the same");
            }

    This way java checks if area1 == area2

    Good luck

  5. #5
    Join Date
    Dec 2004
    Posts
    46
    Thanks for your help

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center