I am always getting NoSuchElement Exception on Codeshef IDE, but my code is running successfully on other online & offline IDE. Please help me, I am not able to submit my codes

//Please check & reply as soon as possible
import java.util.;
import java.lang.
;
import java.io.*;
class Coins
{
public static void main(String args[])throws IOException
{
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
int n,c1,c2,c3,sp=0;
while(t>0)
{
n=sc.nextInt();
c1=n/2;
c2=n/3;
c3=n/4;
sp=c1+c2+c3;
System.out.println(n>sp?n:sp);
t–;
}
}
}

brother it is getting because your are not giving input .
In Codechef Run button means it will first compile & then Run.

2 Likes

your code compile successfully but when it runs it don’t find any input.

2 Likes

Thank you, it’s working now :slight_smile:

What modification u did in ur code to solve this exception @nikhil510

he wasn’t taking input at the right places i think…enter a statement to take input
like for python

a = int(input())

for C++

//I am newbie in C++
int t
cin >> t

something like this…dunno for java tho

As suggested by @codedirector, I just wasn’t taking input while running.