-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjava2.java
More file actions
41 lines (34 loc) · 1.55 KB
/
java2.java
File metadata and controls
41 lines (34 loc) · 1.55 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
import java.util.Scanner;
public class java2 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("How many elements you want to enter: ");
int size = input.nextInt();
int[] numbers = new int[size];
int max = Integer.MIN_VALUE, min = Integer.MAX_VALUE;
int maxIndex = -1, minIndex = -1;
for (int i = 0; i < size; i++) {
System.out.print("Enter element " + (i + 1) + ": ");
numbers[i] = input.nextInt();
if (numbers[i] > max) {
max = numbers[i];
maxIndex = i;
}
if (numbers[i] < min) {
min = numbers[i];
minIndex = i;
}
}
System.out.println("\n----------------Max element----------------");
System.out.println("max number is " + max);
System.out.println("Index of max number is " + (maxIndex + 1));
System.out.println("\n----------------Minimum element----------------");
System.out.println("Minimum number is " + min);
System.out.println("Index of min number is " + (minIndex + 1));
System.out.println("\n----------------Diff. b/w min and max----------------");
System.out.println("The difference is : " + Math.abs(max - min));
System.out.println("\n----------------Diff. b/w min and max indexes----------------");
System.out.println("The difference of indices is : " + Math.abs(maxIndex - minIndex));
input.close();
}
}