-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathspan.java
More file actions
33 lines (33 loc) · 757 Bytes
/
span.java
File metadata and controls
33 lines (33 loc) · 757 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.Scanner;
public class span
{
public static void main(String[] args)
{
Scanner scn = new Scanner(System.in);
int n = scn.nextInt();
int [] arr = new int[n];
for(int i = 0;i<arr.length;i++)
{
arr[i]= scn.nextInt();
}
diff(arr);
scn.close();
}
public static void diff(int [] arr)
{
int max = arr[0];
int min = arr[0];
for (int i = 1;i<arr.length;i++)
{
if (max<arr[i])
{
max = arr[i];
}
if (min>arr[i])
{
min = arr[i];
}
}
System.out.println("difference of max and min is "+(max-min));
}
}