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

Thread: (TOTAL BEGINNER)Stupid problem but still...

  1. #1
    Junior Member
    Join Date
    Jan 2012
    Posts
    6
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Unhappy (TOTAL BEGINNER)Stupid problem but still...

    Well I'm totally new to java so I may be posting stupid/easy to find questions, but could someone please tell me why this happens?

    Ok so this is my code :

    int age = 50
    System.out.println(age == 50 ? "Your 50" : "Your not 50");

    This code even when age is 50 it says "Your not 50"...It's always "Your not 50"...

    What I want to do is : I want when I change the age variable to change the output to either "your 50" (if age is 50) or "Your not 50"(if age isn't 50)

    Is it completely mistake?


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: (TOTAL BEGINNER)Stupid problem but still...

    The above code does not compile without a trivial correction (missing ; )
    When I execute it, the output is: Your 50

    I don't understand your problem.

  3. The Following 2 Users Say Thank You to Norm For This Useful Post:

    ggmike (January 5th, 2012), qwerty53 (January 5th, 2012)

  4. #3
    Junior Member
    Join Date
    Jan 2012
    Posts
    6
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: (TOTAL BEGINNER)Stupid problem but still...

    OHH god I know what it was wrong XD

    The code right above this one was:

    System.out.println(age + age++);

    Which made my age + 1 so when I put 50 it was 51 thats why it was giving me that I wasn't 50..
    Sorry for that and thanks Norm for answering

  5. #4
    Junior Member
    Join Date
    Jan 2012
    Posts
    16
    Thanks
    2
    Thanked 2 Times in 2 Posts

    Default Re: (TOTAL BEGINNER)Stupid problem but still...

    Didn't understand what are u really doing, but try using if() i guess:
    i will write an example:

    int age= 50;
     
    if(age==50)
        System.out.println("You are 50");
    else
        System.out.println("You aren't 50")

    hope could help
    Last edited by Nhedro; January 5th, 2012 at 10:25 AM.

  6. The Following User Says Thank You to Nhedro For This Useful Post:

    ggmike (January 5th, 2012)

  7. #5
    Junior Member
    Join Date
    Jan 2012
    Posts
    6
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: (TOTAL BEGINNER)Stupid problem but still...

    Quote Originally Posted by Nhedro View Post
    Didn't understand what are u really doing, but try using if() i guess:
    i will write an example:

    int age= 50;
     
    if(age==50)
        System.out.println("You are 50");
    else
        System.out.println("You aren't 50")

    hope could help
    WOW I didn't thought of that... Nice, thanks mate!

  8. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: (TOTAL BEGINNER)Stupid problem but still...

    That is the expanded version of what you have in post#1.

  9. #7
    Junior Member
    Join Date
    Jan 2012
    Posts
    6
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: (TOTAL BEGINNER)Stupid problem but still...

    Quote Originally Posted by Norm View Post
    That is the expanded version of what you have in post#1.
    Yeah I just learned the if and switch statement....(or I believe so)

  10. #8
    Member
    Join Date
    Dec 2011
    Location
    United States
    Posts
    94
    My Mood
    Amused
    Thanks
    5
    Thanked 8 Times in 8 Posts

    Default Re: (TOTAL BEGINNER)Stupid problem but still...

    Just for a side note: Very important but almost easy to forget things in Java includes: (- the semicolon, and also the ({})- opening and closing curly braces in code blocks and the use of () - opening and closing parenthesis in #constructors and methods. Hope this gives you more information.

  11. The Following User Says Thank You to elisha.java For This Useful Post:

    ggmike (January 6th, 2012)

Similar Threads

  1. what the stupid problem in using netbeans
    By ms_ceng in forum Java IDEs
    Replies: 3
    Last Post: December 13th, 2011, 03:28 AM
  2. Beginner problem with a do-while.
    By Eliijahh in forum Loops & Control Statements
    Replies: 3
    Last Post: November 21st, 2011, 01:28 PM
  3. Beginner Problem
    By jokibaer in forum What's Wrong With My Code?
    Replies: 7
    Last Post: August 15th, 2011, 06:34 PM
  4. Beginner Problem
    By Melvrick in forum What's Wrong With My Code?
    Replies: 2
    Last Post: August 15th, 2011, 12:29 PM
  5. Replies: 1
    Last Post: May 3rd, 2011, 09:46 AM

Tags for this Thread