-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkthelement.java
More file actions
37 lines (36 loc) · 991 Bytes
/
Copy pathkthelement.java
File metadata and controls
37 lines (36 loc) · 991 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
34
35
36
37
package matrix;
import java.util.Scanner;
import java.util.Arrays;
public class kthelement {
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
int n;
System.out.println("enter the number of rows and columns : ");
n=s.nextInt();
int arr[][]=new int[n][n];
//input array
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
System.out.println("enter the element : "+i+" "+j);
arr[i][j]=s.nextInt();
}
}
int k;
System.out.println("enter the element : ");
k=s.nextInt();
int index=0;
int arr2[]=new int[n*n];
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
arr2[index]=arr[i][j];
index++;
}
}
Arrays.sort(arr2);
System.out.println(arr2[k-1]);
}
}