-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path024-Find-Largest-of-Three-Numbers.java
More file actions
80 lines (60 loc) · 2.7 KB
/
Copy path024-Find-Largest-of-Three-Numbers.java
File metadata and controls
80 lines (60 loc) · 2.7 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
75
76
77
78
79
80
/*
* ============================================================================
* Program Name : Find Largest of Three Numbers
* File Name : 024-Find-Largest-of-Three-Numbers.java
* Class Name : FindLargestOfThreeNumbers
*
* Description:
* This program demonstrates how to find the largest of three numbers
* entered by the user using the if-else-if ladder.
*
* Objective:
* - Understand user input using the Scanner class.
* - Learn how to compare three 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 FindLargestOfThreeNumbers {
// 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();
// Ask the user to enter the third number.
System.out.print("Enter the Third Number: ");
// Read the third number entered by the user.
int thirdNumber = scanner.nextInt();
// Check whether the first number is greater than or equal to the other two numbers.
if (firstNumber >= secondNumber && firstNumber >= thirdNumber) {
// Display the first number as the largest number.
System.out.println("Largest Number: " + firstNumber);
// Example Output: Largest Number: 95
}
// Check whether the second number is greater than or equal to the other two numbers.
else if (secondNumber >= firstNumber && secondNumber >= thirdNumber) {
// Display the second number as the largest number.
System.out.println("Largest Number: " + secondNumber);
// Example Output: Largest Number: 120
}
// Execute this block if the third number is the largest.
else {
// Display the third number as the largest number.
System.out.println("Largest Number: " + thirdNumber);
// Example Output: Largest Number: 150
}
// Close the Scanner object to release system resources.
scanner.close();
}
}