-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMaximumofThree.java
More file actions
37 lines (27 loc) · 1008 Bytes
/
Copy pathMaximumofThree.java
File metadata and controls
37 lines (27 loc) · 1008 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
26
27
28
29
30
31
32
33
34
35
36
37
//Write a java program that finds and prints the maximum of three numbers.
import java.util.Scanner;
public class MaximumOfThree {
public static void main(String[] args) {
// Create a Scanner object to read 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();
// Determine the maximum number
double max = num1;
if (num2 > max) {
max = num2;
}
if (num3 > max) {
max = num3;
}
// Print the maximum number
System.out.println("The maximum number is: " + max);
// Close the scanner
scanner.close();
}
}