-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathLargest Among 3 Numbers Programs
42 lines (31 loc) · 1.16 KB
/
Largest Among 3 Numbers Programs
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
import java.util.Scanner;
public class LargestAmongThree {
public static void main(String[] args) {
// Create a Scanner object to read user input
Scanner scanner = new Scanner(System.in);
// Prompt the user to enter three numbers
System.out.print("Enter the first number: ");
double num1 = scanner.nextDouble();
System.out.print("Enter the second number: ");
double num2 = scanner.nextDouble();
System.out.print("Enter the third number: ");
double num3 = scanner.nextDouble();
// Find the largest number among the three
double largest = findLargest(num1, num2, num3);
// Display the largest number
System.out.println("The largest number is: " + largest);
// Close the scanner
scanner.close();
}
// Function to find the largest number among three numbers
public static double findLargest(double num1, double num2, double num3) {
double largest = num1;
if (num2 > largest) {
largest = num2;
}
if (num3 > largest) {
largest = num3;
}
return largest;
}
}