Whats wrong in this?

import java.util.Scanner;
public class Main {
public static void main(String args[]) {
Scanner scn= new Scanner(System.in);
int n= scn.nextInt();
int p,rem,ans=0;
for(int i=1;i<=n;i++){
int num=scn.nextInt();
while(num!=0){
rem=num%10;
int x=((int)rem*(Math.pow(2,p)));
num=num/10;
p++;
ans=ans+x;}
System.out.println(ans);

}

@Gokulsood
I went through your code,
Your logic was almost correct,just you need to understand the diff between local and global variable.
Let me explain through your code
int p,rem,ans all three are declared as global.
But,p and ans varies for each test case as there may be 1000 test cases.So we need to keep p=0,and ans=0 for every test case. i.e make it local inside the for loop of the test cases.
Secondly,Please use long everywhere as the Number is upto 10^15.
Update Code:


Please hit like if I gave satisfactorily explanation to your doubt and mark it as resolved.
If further remains in this problem,ask them here.