-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmax.java
40 lines (40 loc) · 943 Bytes
/
max.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
import java.util.*;
class max
{
public static void main(String[] args)
{
try
{
Scanner input = new Scanner(System.in);
System.out.print("enter the size of the array:- ");
int size = input.nextInt();
int[] arr = new int[size];
System.out.println("enter the values in the array:- ");
for(int i=0;i<size;i++)
{
arr[i] = input.nextInt();
}
Arrays.sort(arr);
System.out.print("enter the Mth max number:- ");
int m = input.nextInt();
System.out.print("enter the Nth min number:- ");
int n = input.nextInt();
int max=0,min=0;
if(m==0)
System.out.println("please enter the valid input");
else
{
max = arr[arr.length-m];
min = arr[n-1];
System.out.println("the max is "+max);
System.out.println("the min is "+min);
System.out.println("the sum is: "+(max+min));
System.out.println("the min is: "+(max-min));
}
}
catch(Exception e)
{
System.out.println("Enter only numbers");
}
}
}