Maximum remaining-long challenge april division 2

when i code in codechef online compiler then runtime error are found,
i don’t know why!!

this type of error are occur

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)

@sunny0712 use try & catch blocks whenever using Scanner class as i/p

1 Like

You might be trying to take input when it doesn’t even exists like your program would be reading 6 numbers when there would exist only 5 in the input. Check your loops in which you are taking input and also check whether you are providing the right input data.

1 Like

but if i run this code on the pc compiler then this one easily run bro without showing any error

Its coz of improper formatting of inputs by codechef like extra space or carriage return etc.

I had really bad experience due to this

Solution is not to read it int by int but rather read complete line and then split the string

String[] st = br.readLine().split(" ");

Don’t use scanner for cp. Its too slow. use bufferedReader

1 Like