If statement in Java || Java Tutorials || Mr.DarkTecy

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
*/
If statement in Java || Java Tutorials || Mr.DarkTecy If statement in Java || Java Tutorials || Mr.DarkTecy Reviewed by Salman Shaikh on April 12, 2020 Rating: 5
Powered by Blogger.