-
Notifications
You must be signed in to change notification settings - Fork 0
/
NSmall.java
41 lines (30 loc) · 1002 Bytes
/
NSmall.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
import java.util.Scanner;
public class NSmall {
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
System.out.println("Enter the array size");
int n = sc.nextInt();
int nums[] = new int[n];
System.out.println("Enter the array elements");
for(int i=0; i<n; i++)
{
nums[i]=sc.nextInt();
}
System.out.println("Enter the value of k");
int k = sc.nextInt();
int temp;
for(int i=0;i<n;i++)
{
for(int j=i+1;j<n;j++)
{
if(nums[j]<nums[i])
{
temp=nums[i];
nums[i]=nums[j];
nums[j]=temp;
}
}
}
System.out.println(k+"th smallest number is "+nums[k-1]);
}
}