29 If else statement in Java

Syntax:
           if( condion ){
                 Statements;
           }
           else{
                Statements;
           }

In this program we compare 2 numbers and find largest ones using if else.

4IFelse.java

class IFelse{

public static void main(String args[]){

int a=10 , b=20 ;

System.out.println("a= "+a+" b= "+b);

if(a>b){
System.out.println("A is greater");
}
else{
System.out.println("B is greater");
}
}
}

Output: 

Previous
Next Post »