If statement in Java.
If statement in Java

- It is used to test the condition.
- If the condition is true its body will execute otherwise does not execute.
class Easy
{
public static void main(String[] args)
{
int x=10;
if(x>5)
{
System.out.println("x is greater than 5");
}
}
}
/*
### Output ###
x is greater than 5
*/
import java.util.Scanner;
class Easy
{
public static void main(String[] args)
{
Scanner in=new Scanner(System.in);
int no;
System.out.println("Enter any number");
no=in.nextInt();
if(no>0)
System.out.println("number is positive");
if(no<0)
System.out.println("number is negative");
if(no==0)
System.out.println("number is zero");
}
}
/*
### Output ###
Enter any number
-5
number is negative
*/