-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsorting.java
More file actions
63 lines (49 loc) · 1.09 KB
/
Copy pathsorting.java
File metadata and controls
63 lines (49 loc) · 1.09 KB
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
61
62
63
/*Write a program to sort the given array and
* Find the Kth largest and Kth smallest number in an array
*/
import java.util.*;
public class sorting {
public static void main(String[] args)
{
int n;
Scanner input=new Scanner(System.in);
System.out.print("enter the number of elements : ") ;
n=input.nextInt();
int []x= new int[n];
System.out.println();
System.out.print("ENTER ELEMENTS : ");
for(int i=0;i<n;i++)
{
x[i]=input.nextInt();
}
System.out.println();
input.close();
System.out.println();
System.out.print("sorted array is ");
for(int i=0;i<n-1;i++)
{
for(int j=i+1;j<n;j++)
{
if(x[i]>x[j])
{
int temp;
temp=x[i];
x[i]=x[j];
x[j]=temp;
}
}
}
for(int i=0;i<n;i++)
{
System.out.print(x[i]+ " , " );
}
for(int i=0;i<n;i++)
{
System.out.println();
System.out.print("MAX array in element is : " +x[n-1]);
System.out.println();
System.out.print("MIN element in array is : " +x[0]);
break;
}
}
}