All the Notes in one Place. Download our Official App from Google Play.

Java If Statement

                                    Java If Statement

The Java if statement works much like the if statement in any other language.Its simplest form is 
if(condition)statement;


/*
         This is a Simple Program Showing Use of if Control Structure.
          Program developed by #Asad Hussain
         This file name is "ifsample.java".
*/
import java.util.*;

public class ifsample {

public static void main(String args[]) {

int x,y;
x=10;
y=30;

if(x < y);
System.out.println("x="+x);
System.out.println("y="+y);
System.out.println("x is less than y");

x=x*3;
if(x == y);
System.out.println("x="+x);
System.out.println("y="+y);
System.out.println("x now equal to y");

x=x*3;
if(x > y);
System.out.println("x="+x);
System.out.println("y="+y);
System.out.println("x now greater than y");

}
}

Output of Given Program:
Java Program showing use of if control statement by Asad Hussain


Written By: Asad Hussain

Post a Comment

Previous Post Next Post