-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathp021arrayBigger.java
More file actions
45 lines (29 loc) · 1006 Bytes
/
p021arrayBigger.java
File metadata and controls
45 lines (29 loc) · 1006 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
42
43
44
45
import java.util.*;
public class p021arrayBigger {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the length of array ");
int length = sc.nextInt();
int a[] = new int[length];
for (int i = 0; i < length; i++) {
System.out.println("Enter the number of array at position " + i + " = ");
a[i] = sc.nextInt();
}
System.out.print("Array is - [ ");
for (int i = 0; i < length; i++) {
System.out.print(a[i] + " ");
}
System.out.print(" ] ");
int smallest = a[0];
int bigger = a[0];
System.out.println(" ");
for (int i = 0; i < 5; i++) {
if (a[i] < smallest)
smallest = a[i];
else if (a[i] > bigger)
bigger = a[i];
}
System.out.println("smallest=" + smallest);
System.out.println("bigger=" + bigger);
}
}