-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGreatestOfTwoNum.java
More file actions
25 lines (19 loc) · 902 Bytes
/
GreatestOfTwoNum.java
File metadata and controls
25 lines (19 loc) · 902 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import java.util.Scanner; // Import Scanner class for user input
public class GreatestOfTwoNum {
// Function to return the greater of two numbers
public static int getGreater(int a, int b) {
return (a > b) ? a : (a < b) ? b : a; // Using ternary operator
}
public static void main(String[] args) {
try (Scanner scanner = new Scanner(System.in)) { // Creating Scanner object for user input
// Asking user to enter first number
System.out.println("Enter the value of a: ");
int a = scanner.nextInt();
// Asking user to enter second number
System.out.println("Enter the value of b: ");
int b = scanner.nextInt();
// Printing the greater number
System.out.println("The greater number is: " + getGreater(a, b));
}
}
}