Write a programme to compare two given numbers and display which of
them greater or whether they are equal.
IN JAVA....
Answers
Answer:
Easy method (without inputs):
public class Main {
public static void main(String[] args) {
int a = 10; // your numbers here
int b = 20;
if(a>b) {
System.out.println(a + " (First number) is greater");
} else if(b>a) {
System.out.println(b + " (Second number) is greater");
} else {
System.out.println("Both are equal");
}
}
}
Better Method (with input):
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter first number");
num1 = scanner.nextInt();
System.out.println("Enter second number");
num2 = scanner.nextInt();
if(num1>num2) {
System.out.println(num1 + " (First number) is greater");
} else if(num2>num1) {
System.out.println(num2 + " (Second number) is greater");
} else {
System.out.println("Both are equal")
}
}
}