-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogram31.java
More file actions
38 lines (25 loc) · 901 Bytes
/
Copy pathprogram31.java
File metadata and controls
38 lines (25 loc) · 901 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
// Find the largest and smallest element in an array.
public class program31 {
public static void main(String[] args) {
int arr[] = {10,20,30,60,50,120};
System.out.print("Given Elements : ");
for(int i=0; i < arr.length; i++){
System.out.print(arr[i]+" ");
}
System.out.println(" ");
// to check largest.
int max = arr[0];
for(int i =0; i<arr.length; i++){
if(arr[i]>max){
max = arr[i];
}
}System.out.println("Largest Element : " + max );
// to check smallest.
int min = arr[0];
for(int i =0; i<arr.length; i++){
if(arr[i]<min){
min = arr[i];
}
} System.out.println("Smallest Element : " + min );
}
}