Von Neuman Loves Binary

why my code is not passing test cases
import java.util.Scanner;
public class Main {
public static void main(String args[]) {
Scanner scn =new Scanner(System.in);
int num=scn.nextInt();
int res=binarytodecimal(num);
System.out.println(res);

}
public static int binarytodecimal(int n){
    int ans=0,mul=1;
    while(n!=0){
        int rem=n%10;
        ans=ans+(rem*mul);
        n=n/10;
        mul=mul*2;
    }
    return ans;
}

}

there n no. of cases
you r only taking a single case

pls, see the input format
your code is absolutely correct.

hope this will help u
pls rate my work so that i can improve myself.

how to include the remaining cases

Scanner scn =new Scanner(System.in);
int n=scn.nextInt();
while(n–>0){
int num=scn.nextInt();
int res=binarytodecimal(num);
System.out.println(res);
}

take the inputs for the given times
and then calculate the result for the given i/p

hope this will help u
pls rate my work so that i can improve myself

what is n used for
and also it is showing error that
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.nextLong(Scanner.java:2222)
at java.util.Scanner.nextLong(Scanner.java:2182)
at Main.main(Main.java:7)
and here is my revised code plz help
import java.util.Scanner;
public class Main {
static Scanner scn =new Scanner(System.in);
public static void main(String args[]) {
long n=scn.nextLong();
while(n>=0){
long num=scn.nextLong();
long res=binarytodecimal(num);
System.out.println(res);
}
}
public static long binarytodecimal(long n){
long ans=0,mul=1;
while(n!=0){
long rem=n%10;
ans=ans+(remmul);
n=n/10;
mul=mul
2;
}
return ans;
}
}

pls see the changes which i have made

n is used for multiple inputs simultaneously.
as shown in the given test case.
4 -----> n
101
1111
00110
111111
4 times ur code is executing for a given binary no.

i hope this will help u
pls rate my work so that i can improve myself.

import java.util.Scanner;
public class Main {
static Scanner scn =new Scanner(System.in);
public static void main(String args[]) {
long n=scn.nextInt();
while(n>0){
long num=scn.nextLong();
long res=binarytodecimal(num);
System.out.println(res);
n–;
}
}
public static long binarytodecimal(long n){
long ans=0,mul=1;
while(n!=0){
long rem=n%10;
ans=ans+(remmul);
n=n/10;
mul=mul
2;
}
return ans;
}
}

import java.util.Scanner;
public class Main {
static Scanner scn =new Scanner(System.in);
public static void main(String args[]) {
long n=scn.nextInt();
while(n>0){
long num=scn.nextLong();
long res=binarytodecimal(num);
System.out.println(res);
n–;
}
}
public static long binarytodecimal(long n){
long ans=0,mul=1;
while(n!=0){
long rem=n%10;
ans=ans+(remmul);
n=n/10;
mul=mul
2;
}
return ans;
}
}