Jump to content

If Statement in Java

- - - - -

  • Please log in to reply
5 replies to this topic

#1
arunjib

arunjib

    Learning Programmer

  • Members
  • PipPipPip
  • 76 posts
Let us start a thread on ' if ' statement in Java.

#2
Sinipull

Sinipull

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 386 posts
Why would we want to start that thread? There isn't much to discuss.

#3
arunjib

arunjib

    Learning Programmer

  • Members
  • PipPipPip
  • 76 posts
For a beginer we can start it. [excuse me if i do anything wrong.]
1. if(condition)
<statement>;

2. if(condition)
<statement>;
if(condition)
<statement>;

3. if(condition)
<statement1>;
<statement2>;

and we can progress step by step.

Would it be helpful for a beginer? Please reply.



Sinipull said:

Why would we want to start that thread? There isn't much to discuss.


#4
Sinipull

Sinipull

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 386 posts
You are doing it wrong, you can't add two statements after the if-clause without using curly brackets

if(condition){
    statement1;
    statement2;
} else {
    statement3;
}
this would be the right syntax.

#5
arunjib

arunjib

    Learning Programmer

  • Members
  • PipPipPip
  • 76 posts
Please mention sl number. Are you talking about number 3?

Sinipull said:

You are doing it wrong, you can't add two statements after the if-clause without using curly brackets


if(condition){

    statement1;

    statement2;

} else {

    statement3;

}

this would be the right syntax.


#6
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,118 posts
  • Location:Vancouver, Eh! Cleverness: 200
Yes, they have mentioned two statements after the if clause without curly bracket, so you can assume it is number three of which does not work.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users