-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMaxAndMin.java
More file actions
41 lines (30 loc) · 1014 Bytes
/
MaxAndMin.java
File metadata and controls
41 lines (30 loc) · 1014 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
38
39
40
41
import java.util.Scanner;
import static java.lang.Math.*;
//finds the maximum and minimum number from input of 5 numbers
public class MaxAndMin {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("please type in 5 numbers");
int n1 = in.nextInt();
int n2 = in.nextInt();
int n3 = in.nextInt();
int n4 = in.nextInt();
int n5 = in.nextInt();
// find the largest number
int maxThree = maxOf3(n1,n2,n3);
int max = maxOf3(maxThree,n4,n5);
//find the smallest number
int minThree = minOf3(n1,n2,n3);
int min = minOf3(minThree,n4,n5);
System.out.println("Maximum: " + max);
System.out.println("Minimum: " + min);
}
public static int maxOf3(int r, int s, int t) {
int maximum = max(r,max(s,t));
return maximum;
}
public static int minOf3(int r, int s, int t) {
int minimum = min(r,max(s,t));
return minimum;
}
}