-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path023-Find-Largest-of-Two-Numbers.java
More file actions
74 lines (56 loc) · 2.37 KB
/
Copy path023-Find-Largest-of-Two-Numbers.java
File metadata and controls
74 lines (56 loc) · 2.37 KB
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
* ============================================================================
* Program Name : Find Largest of Two Numbers
* File Name : 023-Find-Largest-of-Two-Numbers.java
* Class Name : FindLargestOfTwoNumbers
*
* Description:
* This program demonstrates how to find the largest of two numbers
* entered by the user using the if-else statement.
*
* Objective:
* - Understand user input using the Scanner class.
* - Learn how to compare two numbers.
* - Identify the largest number using conditional statements.
*
* Author : Shaik Mahaboob Basha
* Repository : 01-Core-Java
* Folder : 08-Java-Programs
* ============================================================================
*/
import java.util.Scanner;
public class FindLargestOfTwoNumbers {
// The main() method is the entry point of every Java application.
public static void main(String[] args) {
// Create a Scanner object to read input from the keyboard.
Scanner scanner = new Scanner(System.in);
// Ask the user to enter the first number.
System.out.print("Enter the First Number: ");
// Read the first number entered by the user.
int firstNumber = scanner.nextInt();
// Ask the user to enter the second number.
System.out.print("Enter the Second Number: ");
// Read the second number entered by the user.
int secondNumber = scanner.nextInt();
// Check whether the first number is greater than the second number.
if (firstNumber > secondNumber) {
// Display the first number as the largest number.
System.out.println("Largest Number: " + firstNumber);
// Example Output: Largest Number: 50
}
// Check whether the second number is greater than the first number.
else if (secondNumber > firstNumber) {
// Display the second number as the largest number.
System.out.println("Largest Number: " + secondNumber);
// Example Output: Largest Number: 75
}
// Execute this block if both numbers are equal.
else {
// Display that both numbers are equal.
System.out.println("Both numbers are Equal.");
// Example Output: Both numbers are Equal.
}
// Close the Scanner object to release system resources.
scanner.close();
}
}