Introduction:-
Today we will be having a look on the java if-else statement and we shall see a sample program a new thing about this post that there will be a download link to the source- code of the program so you can have full access to the code .To implement your programing skills on it and if you wish to share the code genrated by you feel free to comment down below.What is if-else statement?
if-else statement is basically the conditional statement where only one we be executed if the condition evaluates true the code inside the if statement shall be executed or if the condition evalutes false the else statement shall be executed . Now the condition is written inside the if statement and there is no condition in the else block.
What is the syntax of if-else in java?
Syntax:-
if (condition){
statement 1
statement 2
statement 3
.............
}
else{
statment 1
statement 2
.............
}
So the above given syntax is just a simple if-else no ladder or any-other type of if-else is given. For the ladder there will be a seprate post so check for future updates.
How to write a simple java if-else program?
Code Statement :-Program is about finding the largest of two number.
Code:-
class condition{
public static void main(String[] args){
int a = 5;
int b = 6;
if (a>b){
System.out.println("The Greatest of the number is"+a);
}
else{
System.out.println("The Greatest number is "+b);
}
}
}
Now save this file as "condition.java" and then run using cmd or any ide.The output of the above program is given bellow.
OUTPUT:-
The Greatest of the number is 6
So this post was all about the if-else statement in the next post there will be about the ladder if else.If you found this post usefull do share with friends and comment down bellow and do check other java post.
Comments
Post a Comment