No matter what I do , I am not able to. remove this NZEC and exception. Code runs fine in eclipse.
Please help.
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)
/* package codechef; // don’t place package name! */
import java.util.;
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) throws java.lang.Exception
{ Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t>0) {
t--;
int n = 0;
int k = 0;
n = sc.nextInt();
k = sc.nextInt();
int mod = modulus(k,n);
int diff = difference(mod, n);
if(checkEqual(mod,diff)) {
System.out.println(2*diff - 1);
}
else if(checkLess(mod,diff)) {
System.out.println(2*mod);
}
else {
System.out.println(2*diff);
}
}
// if (k%n == 0) {
// System.out.println(0);
// }
// else {
//
// long ourRes = giveRes(k,n);
// System.out.println(ourRes);
//
//
//
// }
//
}
public static int modulus(int k, int n) {
return k%n;
}
public static int difference(int k, int n) {
return n-k;
}
public static boolean checkEqual(int l, int d) {
return l==d;
}
public static boolean checkLess(int l, int d) {
return l<d;
}
public static long giveRes(long k, int n) {
long rem = k%n;
if(rem<=n/2){return (rem*2);}
else {return ((n-rem)*2);
}
}
}