Syntax:
if(condition) statement;
In this program we compare two numbers and find largest ones/greatest ones/max ones.
3IFsample.java
class IFsample{
public static void main(String args[]){
int a=20,b=30;
System.out.println("A= "+a+" B= "+b);
if(a>b)
System.out.println("A is greater");
if(a<b)
System.out.println("B is greater");
if(a==b)
System.out.println("Both are equal");
}
}
if(condition) statement;
In this program we compare two numbers and find largest ones/greatest ones/max ones.
3IFsample.java
class IFsample{
public static void main(String args[]){
int a=20,b=30;
System.out.println("A= "+a+" B= "+b);
if(a>b)
System.out.println("A is greater");
if(a<b)
System.out.println("B is greater");
if(a==b)
System.out.println("Both are equal");
}
}
Output: