1

I keep getting this run time exception on codechef compiler, don't know what i am doing wrong. I know the problem is in Scanner class but couldn't figure out what is it ? (Don't want to use Buffered Reader)

import java.util.*;
import java.lang.*;
import java.io.*;
class Codechef
{
    public static void main (String[] args) throws java.lang.Exception
    {

        Scanner in = new Scanner(System.in);
        int t = in.nextInt();
        for (int t_i=0;t_i<t;t_i++ )
        {

        long n = in.nextLong();
        long x = in.nextLong();
        long rem=n%x;
        System.out.println(rem);
        }

    }
}

Input: 1 10 3

Gives run time exception.

  • add the complete stacktrace and the data you are enter please – Jens Feb 02 '17 at 11:13
  • 1
    your code is working fine by me.... are you sure you are runing the right app?? – ΦXocę 웃 Пepeúpa ツ Feb 02 '17 at 11:17
  • Copying your code and using the input you mentioned (1, 10, 3) it prints the expected result (1). I don't see a problem here? – Thomas Böhm Feb 02 '17 at 11:17
  • updated data, don't know what do you mean by stacktrace. – Vishnu Hari Dadhich Feb 02 '17 at 11:17
  • no problem with the code @VishnuHariDadhich the output is `1`. – jack jay Feb 02 '17 at 11:20
  • Using CodeChef ide, When i use custom input and provide given inputs, it works fine but when i simply press run it shows these exceptions 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:14) – Vishnu Hari Dadhich Feb 02 '17 at 11:20
  • @defaultlocale thanks for the duplicate, it could b found there. – Vishnu Hari Dadhich Feb 02 '17 at 11:22
  • @VishnuHariDadhich you should debug your program first instead of asking on SO, look at this videos https://www.youtube.com/watch?v=i_Gonsk_qGA https://www.youtube.com/watch?v=9gAjIQc4bPU put the breakpoints on the lines in the that files you see in your error log – user1097772 Feb 02 '17 at 11:27
  • @user1097772 i found no error in debugger, for some reason this compiler doesn't work with my code. – Vishnu Hari Dadhich Feb 02 '17 at 11:33

0 Answers0