I have written the code for the CodeChef: Practical coding for everyone problem but it is giving me error as
execption in main thread java.util.NosuchExeption Exception in thread “main” java.util.NoSuchElementException
at java.util.Scanner.throwFor(Scanner.java:862)
at java.util.Scanner.next(Scanner.java:1485)
at java.util.Scanner.nextInt(Scanner.java:2117)
at java.util.Scanner.nextInt(Scanner.java:2076)
at Codechef.main(Main.java:13)
my code is like this
import java.util.Scanner;
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)
{
Scanner sc= new Scanner(System.in);
int tcases= sc.nextInt();
for(int m=1; m<=tcases; m++)
{
// TODO Auto-generated method stub
int length=sc.nextInt();;
int a[] = new int[length];
for(int j=0; j<length-1; j++)
a[j] = sc.nextInt();
String s1="";
for(int i=0; i<length-1; i++)
{
int first=a[i];
int last=a[i+1];
int count=0;
while(i<length && a[i]+1==a[i+1])
{
count++;
last=a[i+1];
i++;
}
if(count>=2)
s1=s1.concat(first+"..."+last+",");
else
s1=s1.concat(first+","+last+",");
}
String s2= s1.substring(0,s1.length()-1);
System.out.println(s2);
}
sc.close();
}
}