DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 5 of 5
  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

Bookmarks

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


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links