if else statement in Java
Skip to main content

if else statement in Java


if else statement in Java, if else java, if statement java, if else program in java, conditionals java, conditional statements in java, if else if statement in java, if statements in java examples



If else statement in Java

If else statement in Java:- In this tutorial is explain about how to use if else conditions statements with explanation and given example of Java Programming.


If else Statement:-  If statement is conditional branch statement. Its can be used to program execution through two different paths. If statement closed with curly braces.  The conditions return a Boolean value.

Syntex:-

If(condition){

      // If condition is true then execution this part of program

}else{

// If condition is false then execution this part of program

}


Most Read:- What is looping ? How many types of loop in Java and describe?


Example:-

1.       If condition is true then:-

int a=10;

int b= 6;

if(a>b){

System.out.println(“a is greater then b”);

}else{

System.out.println(“a is smaller then b”);

}

Output:- a is greater then b

2.       If condition is false then:-

       int a=10;

Int b= 6;

if(a<b){System.out.println(“a is greater then b”);

}

else{System.out.println(“a is smaller then b”);

}

Output:- a is smaller then b

 

Nested If….else if :- 

          Example:-

if(condition){

System.out.println(“ if condition is true”);

}

else if(a>b){ 

System.out.println(“(“ if condition is true”);

}else{// if both condition is false then execute this statements

System.out.println(“Both condition is not true”);

}


Write a program in Java to print even or odd number


class ExampleEvenodd{
 Scanner mScanner;
 int mUserValue;

          public static void main(String [] args){
     
           mScanner= new Scanner(System.in);
           System.out.println("Enter Number : ");
           mUservalue=mScanner.nextInt();
           
           if(mUservalue%2==0){
              System.out.println(mUservalue+" is Even Number");
}else{
             System.out.println(mUservalue+" is Odd Number");
         }

    }
}

Post a Comment

0 Comments