My issue
please help me with the error
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:12)
My code
import java.util.*;
import java.lang.*;
import java.io.*;
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
Scanner sc = new Scanner(System.in);
int ntc = sc.nextInt();
StringBuilder str = new StringBuilder();
while(ntc -- > 0) {
int N = sc.nextInt();
int arr [] = new int[N];
for(int i =0; i<N; i++) {
arr[i] = sc.nextInt();
}
int [] freq = new int[101];
for(int i = 0; i<N; i++) {
freq[arr[i]]++;
}
for(int i = 1; i<freq.length; i++) {
int cnt = freq[i];
while(cnt -- > 0) {
str.append(i).append(" ");
}
}
str.append("\n");
}
System.out.println(str.toString());
}
}
Learning course: Jump from 2* to 3*
Problem Link: Counting Sort Practice Problem in Jump from 2* to 3* - CodeChef