Problem Statement :
Subscribe the channel : click here
Approach :
1. Number of element you want to store array .
2. Store element in array as a unsorted manner
3. find the element at Nth smallest element
Code :
import java.util.*;
public class JAVA35 {
public static void main(String[] args) {
Scanner sc=new Scanner (System.in);
System.out.println("Enter your length of array : ");
int n=sc.nextInt();
int arr[]=new int[n];
for(int i=0;i<arr.length;i++){
arr[i]=sc.nextInt();
}
System.out.println("Array ELements are : ");
System.out.println("------------------------");
for(int i:arr){
System.out.println(i+" ");
}
System.out.println("Enter your desire choice (index) : ");
int N=sc.nextInt();
Arrays.sort(arr);
System.out.println(arr[N]);
}
}
Comments
Post a Comment