Mega Code Archive

 
Categories / Java Book / 001 Language Basics
 

0044 Using if statement to compare two variables

public class Main { 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; 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"); } if (x == y){ System.out.println("==="); } } } The output generated by this program is shown here: x is less than y x now equal to y x now greater than y