forked from 790hanu/Annex-qr-code-simulator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmin-max-diff.java
60 lines (51 loc) · 1.52 KB
/
min-max-diff.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import java.util.Scanner;
//This class will calculate the max and min values of the array
class TestArray
{
int MAX(int[]Arry)
{
int maxValue= Arry[0];
for(int i=1;i<Arry.length;i++)
{
if(Arry[i]>maxValue)
{
maxValue=Arry[i];
}
}
return maxValue;//This method will return the max value present in the array.
}
int MIN(int[]Arry)
{
int minValue=Arry[0];
for(int i=1;i<Arry.length;i++)
{
if(Arry[i]<minValue)
{
minValue=Arry[i];
}
}
return minValue;
}
}
public class DifferenceArry
{
public static void main(String[] args)
{
int n;
//It creates scanner object
Scanner sc = new Scanner(System.in);
System.out.print("Enter the array elements:" );
n=sc.nextInt();
int arr[]=new int[n];
for(int i=0;i<arr.length;i++)
{
System.out.print("Enter ["+(i+1)+"] element :" );
arr[i]=sc.nextInt();
}
TestArray obj=new TestArray();
System.out.println("Maximum value in the array is :" +obj.MAX(arr));
System.out.println("Minimum value in the array is :" +obj.MIN(arr));
int diff=obj.MAX(arr)-obj.MIN(arr);
System.out.print("Difference between max and min elements is : " +diff );
}
}