This code was running well in custom input output but producing this error please help!
Error:
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 Main.main(Main.java:13)
My Code:
import java.util.;
import java.lang.;
import java.io.*;
/* Name of the class has to be “Main” only if the class is public. */
public class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner inp = new Scanner(System.in);
int t;
t=inp.nextInt();
while(t!=0){
t = t-1;
int c;
if(inp.hasNextInt()){
c=inp.nextInt();
}else{
c=1;
}
List<Integer> li = new ArrayList<Integer>();
for(int i=1;i<=c;i++)
li.add(i);
if(li.size()==1){
System.out.println(li.get(0));
}
else{
while(li.size()!=1){
int x,y;
x=li.get(0);
y=li.get(li.size()-1);
li.remove(0);
li.set(li.size()-1,x+y+(x*y));
}
}
System.out.println(li.get(0));
}
inp.close();
// your code goes here
}
}
Please if anyone one knows the problem please help