Here is a Java Program to show Comparison Operation on the two variable using If Control Structure
Explanation of Above Java Program:
In above Program we have two variable x and y with value of 10 and 20 respectively .
class IfComparison { public static void main(String args[]) { int x, y; x = 10; y = 20; if(x < y) System.out.println("x is less than y"); x = x * 2;// x= 20 if(x == y) System.out.println("x now equal to y"); x = x * 2; if(x > y) System.out.println("x now greater than y"); // this won't display anything if(x == y) System.out.println("you won't see this"); } } /*************************** * x is less than y * x now equal to y * x now greater than y * ****************************/
Explanation of Above Java Program:
In above Program we have two variable x and y with value of 10 and 20 respectively .
If Syntax
if( Condition){ //code goes here that would execute if condition is true }
- first we compared if X less than y
- We multiply X with 2
- we check to see if they are equal or not
- then again multiply with two
- Check to see if x is greater than y
- Finally we check if two variable equal or not.