How to compare two numbers using if else if statements. - Java Language Basics

Java examples for Language Basics:if

Description

How to compare two numbers using if else if statements.

Demo Code


public class Main {
 
        public static void main(String[] args) {
               //from   w ww.j av a2 s. com
                //declare two numbers to compare
                int num1 = 324;
                int num2 = 234;
               
                if(num1 > num2){
                        System.out.println(num1 + " is greater than " + num2);
                }
                else if(num1 < num2){
                        System.out.println(num1 + " is less than " + num2);
                }
                else{
                        System.out.println(num1 + " is equal to " + num2);
                }
        }
}

Result


Related Tutorials