-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproblem6.java
34 lines (25 loc) · 1003 Bytes
/
problem6.java
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
package sheetArrays;
import java.util.Scanner;
public class problem6 {
public static void main(String[] args) {
System.out.println("Enter size of integer array : ");
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int[] arr = new int[n];
System.out.println("Enter value : ");
arr[0] = in.nextInt();
int smallest = arr[0], largest = arr[0];
for (int i = 1; i < n; i++) {
System.out.println("Enter value : ");
arr[i] = in.nextInt();
if (arr[i] < smallest) {
smallest = arr[i];
}
if (arr[i] > largest) {
largest = arr[i];
}
}
int diffrence=largest-smallest;
System.out.println("The maximum difference between two elements of the said array elements "+diffrence);
}// 2, 3, 1, 7, 9, 5, 11, 3, 5 }//{-10, 4, -9, -5}
}