My issue
Exception in thread “main” java.util.NoSuchElementException
at java.base/java.util.Scanner.throwFor(Scanner.java:937)
at java.base/java.util.Scanner.next(Scanner.java:1594)
at java.base/java.util.Scanner.nextInt(Scanner.java:2258)
at java.base/java.util.Scanner.nextInt(Scanner.java:2212)
at Codechef.main(Main.java:16)
what does it mean
My code
/* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner input=new Scanner(System.in);
int t,min,index,i,pass,students;
t=input.nextInt();
while(t-->=0){
students=input.nextInt();
pass=input.nextInt();
int marks[]=new int[students];
for(i=0;i<students;i++){
marks[i]=input.nextInt();
}
Arrays.sort(marks);
index=students-pass;
min=marks[index];
min--;
System.out.println(min);
}
}
}
Learning course: Sorting using Java
Problem Link: CodeChef: Practical coding for everyone