-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLargestAndSmallestInt.java
More file actions
64 lines (55 loc) · 1.67 KB
/
LargestAndSmallestInt.java
File metadata and controls
64 lines (55 loc) · 1.67 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
package Chapter2;
import java.util.Scanner;
public class LargestAndSmallestInt {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter the first number: ");
int a = input.nextInt();
System.out.println("Enter the second number: ");
int b = input.nextInt();
System.out.println("Enter the third number: ");
int c = input.nextInt();
System.out.println("Enter the fourth number: ");
int d = input.nextInt();
System.out.println("Enter the fifth number: ");
int e = input.nextInt();
double result = large(a, b, c, d, e);
System.out.println("Largest number is: " + result);
double result2 = small(a, b, c, d, e);
System.out.println("Smallest number is: " + result);
}
public static double large(double a, double b, double c,
double d, double e) {
double largestNumber = a;
if (b > largestNumber) {
largestNumber = b;
}
if (c > largestNumber) {
largestNumber = c;
}
if (d > largestNumber) {
largestNumber = d;
}
if (e > largestNumber) {
largestNumber = e;
}
return largestNumber;
}
public static double small(double a, double b, double c,
double d, double e) {
double smallestNumber = a;
if(b < smallestNumber) {
smallestNumber = b;
}
if(c < smallestNumber) {
smallestNumber = c;
}
if (d < smallestNumber) {
smallestNumber = d;
}
if (e < smallestNumber) {
smallestNumber = e;
}
return smallestNumber;
}
}