Showing posts with label If statement. Show all posts
Showing posts with label If statement. Show all posts

Wednesday, January 4, 2012

If Statement in JAVA



If else statement is used to execute some code only if a specified condition is true.If condition is true then the statement will be execute 

Syntax of  If Statement in JAVA

if (condition)
  {
  code to be executed if condition is true
  }

Note : if is written in only lowercase letters. If we use uppercase letter like (IF) it will give error 


Example of if statement

public class IfStatement {

 public static void main(String[] args) {
  int a = 20, b = 30;
  if (a > b)
   System.out.println("a > b");
  if (a < b)
   System.out.println("b > a");
 }
}


Output of This Example

b > a