-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrays_2.java
More file actions
38 lines (29 loc) · 1008 Bytes
/
Arrays_2.java
File metadata and controls
38 lines (29 loc) · 1008 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
import java.util.Scanner;
public class Arrays_2 {
public static void main(String[] args){
Scanner sc= new Scanner(System.in);
System.out.println("Enter the element you require.");
int d= sc.nextInt();
System.out.println("---------------------------------");
System.out.println("Enter the number of values you require in this Array.");
int n= sc.nextInt();
System.out.println("---------------------------------");
int[] array1= new int[n];
for(int i=0;i<n;i++){
array1[i]= sc.nextInt();
}
int min=array1[0];
int max=array1[0];
for(int i=0;i<n;i++){
if(array1[i]< min){
min=array1[i];
}
if(array1[i]> max){
max=array1[i];
}
}
int span= max-min;
System.out.println("The Span of this Array is :- "+ span);
System.out.println("---------------------------------");
}
}