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 2 of 2

Thread: whats wrong with this if and else statement . how can i solve it

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Posts
    1
    My Mood
    Amused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post whats wrong with this if and else statement . how can i solve it

    public class BMI{
    public static void main(String[] args) {
    Double weight = Double.parseDouble(args[0]);
    Double height= Double.parseDouble(args[1]);

    double total=(weight/(height*height))*703;
    System.out.println( total);




    if (total >= 18.5) && (total <= 24.9);{

    System.out.println(" true"); }

    else {
    System.out.println(" false");
    }


  2. #2
    Super Moderator Sean4u's Avatar
    Join Date
    Jul 2011
    Location
    Tavistock, UK
    Posts
    637
    Thanks
    5
    Thanked 103 Times in 93 Posts

    Default Re: whats wrong with this if and else statement . how can i solve it

    Quote Originally Posted by rafina8527 View Post
    if (total >= 18.5) && (total <= 24.9);{
    }
    Not enough parentheses (for an if statement). Semicolon.

    You can also write:Operators (The Java™ Tutorials > Learning the Java Language > Language Basics)
    System.out.println(total >= 18.5 && total <= 24.9)

    It works thanks to the rules of Order of operations - Wikipedia, the free encyclopedia

    Operators (The Java™ Tutorials > Learning the Java Language > Language Basics)

Similar Threads

  1. Whats wrong here?
    By Java Sucks in forum What's Wrong With My Code?
    Replies: 4
    Last Post: June 8th, 2011, 08:33 PM
  2. whats wrong with my if statement
    By semicolon in forum What's Wrong With My Code?
    Replies: 5
    Last Post: May 23rd, 2011, 04:28 PM
  3. could you tell me whats wrong....
    By gonfreecks in forum What's Wrong With My Code?
    Replies: 3
    Last Post: November 6th, 2010, 04:35 PM
  4. help whats wrong
    By silverspoon34 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: October 3rd, 2009, 01:41 AM
  5. [SOLVED] whats wrong with my IDE
    By chronoz13 in forum Java IDEs
    Replies: 2
    Last Post: August 27th, 2009, 06:34 AM