Skip to content

Larger of Two Numbers

Find the greater of two user-provided numbers.

package DSA.Conditional_statements;
import java.util.*;
public class largerof2 {
public static void main(String[] args) {
try (Scanner sc = new Scanner(System.in)) {
System.out.println("Enter two number : ");
int a = sc.nextInt();
int b = sc.nextInt();
if (a >= b) {
System.out.println(a + " is greater");
} else {
System.out.println(b + " is greater");
}
} catch (Exception e) {
System.out.println("Invalid Input");
}
}
}