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: What's up with this if code?

  1. #1
    Junior Member
    Join Date
    Oct 2012
    Posts
    15
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default What's up with this if code?

    System.out.println("Example2c: ");
    int A = 85;
    int B = 65;
    String out = "\tNot a valid input!";
    if (x > A) out = "\tWell done!";
    if (x > B) out = "\tOK!";
    if (x > 0) out = "\tNot good!";
    System.out.println(out);

    I input 90 and it print out "Not good". Wth? 90>85, 90>65, 90>0 so shouldn't it print out all the of them except not a valid input?


  2. #2
    Member
    Join Date
    Mar 2011
    Posts
    66
    My Mood
    Relaxed
    Thanks
    12
    Thanked 4 Times in 4 Posts

    Default Re: What's up with this if code?

    Hey! First of all, I'd like to recommend you take a step back and look at what you've written so far. Get a pen and paper and write out exactly what each thing does. Also, I recommend looking at The if-then and if-then-else Statements (The Java™ Tutorials > Learning the Java Language > Language Basics) and really understand the syntax for the "if" statements.

Similar Threads

  1. How to Translate working code into code with a Tester Class
    By bankoscarpa in forum What's Wrong With My Code?
    Replies: 6
    Last Post: October 15th, 2012, 02:13 PM
  2. Replies: 3
    Last Post: September 3rd, 2012, 11:36 AM
  3. code to refresh and check the code of a webpage..
    By vaggelis in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 7th, 2012, 07:43 AM
  4. problem in my code java code graph editeur
    By kisokiso in forum Java Theory & Questions
    Replies: 5
    Last Post: January 6th, 2012, 08:36 AM
  5. Code is giving an error in console, but there are no errors apparent in the code!
    By JamEngulfer221 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 15th, 2011, 09:30 PM