forked from chennakrishnans/JAVA
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlarge.java
More file actions
31 lines (31 loc) · 747 Bytes
/
Copy pathlarge.java
File metadata and controls
31 lines (31 loc) · 747 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
import java.util.*;
class large
{
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 largest number:- ");
int m = input.nextInt();
int max=0;
if(m<=0)
System.out.println("please enter the valid input");
else{
max = arr[arr.length-m];
System.out.println("the largest number is "+max);
}
}
catch(Exception e)
{
System.out.println("Invalid Due to character or number format exception");
}
}
}