-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrays.java
More file actions
51 lines (40 loc) · 1.36 KB
/
Arrays.java
File metadata and controls
51 lines (40 loc) · 1.36 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
42
43
44
45
46
47
48
49
50
51
import java.util.Scanner;
public class Arrays {
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("---------------------------------");
int ans= Find(array1, d);
System.out.println(ans);
}
public static int Find(int[] array1, int d){
for(int i=0;i<array1.length;i++){
if(array1[i]== d){
System.out.println("The value of the Class-Index :- "+i);
System.out.println("---------------------------------");
}
}
return -1;
}
}