This program compares the two numbers using if else statements.It a very basic question to start with conditional statements.
Input:- 4 5
Output:- 4 is less than 5
Sample Program:-
/**
* @author Dixit
*
*/
public class CompareTwoNumbers {
/**
* @param args
*/
public static void main(String[] args) {
// declare two numbers to compare
int num1 = 4;
int num2 = 5;
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);
}
}
}
Output
4 is less than 5
Enjoy Programming :)
No comments:
Post a Comment