(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 :
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?
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.
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 :)
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:
Code :
int age= 50;
if(age==50)
System.out.println("You are 50");
else
System.out.println("You aren't 50")
hope could help ;)
Re: (TOTAL BEGINNER)Stupid problem but still...
Quote:
Originally Posted by
Nhedro
Didn't understand what are u really doing, but try using if() i guess:
i will write an example:
Code :
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!
Re: (TOTAL BEGINNER)Stupid problem but still...
That is the expanded version of what you have in post#1.
Re: (TOTAL BEGINNER)Stupid problem but still...
Quote:
Originally Posted by
Norm
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):rolleyes:
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.