-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSmallestLargest.java
More file actions
33 lines (29 loc) · 931 Bytes
/
Copy pathSmallestLargest.java
File metadata and controls
33 lines (29 loc) · 931 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
import java.util.*;
public class SmallestLargest {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("How Many Element ou Want To Enter :");
int n = sc.nextInt();
int[] arr = new int[n];
int min = arr[0];
int max = arr[0];
int minindex = 0;
int maxindex = 0;
for (int i = 0; i < arr.length; i++) {
System.out.print("Enter Number = " + i);
arr[i] = sc.nextInt();
}
for (int i = 0; i < arr.length; i++) {
if (min > arr[i]) {
min = arr[i];
minindex = i;
}
if (max < arr[i]) {
max = arr[i];
maxindex = i;
}
}
System.out.println("MinIndex = " + minindex + " MaxIndex = " + maxindex);
sc.close();
}
}