Compilation successfull.but showinhg error when submitting. why?

import java.util.Scanner;
import java.lang.Math;
public class VON_NEUMAN {

public static void main(String[] args) {
      Scanner input=new Scanner(System.in);
      int j,t;
      t=input.nextInt();
      for(j=0;j<t;j++) {    	  
      int n=input.nextInt();
      int length=Integer.toString(n).length();
    	  int i;
    	  double d,c,a,b;
    	  d=0;
    	  for(i=0;i<length;i++) {
    		 
    		  a=n%10;
    		  b=Math.pow(2,i);
    		  
    		  d=a*b+d;
    		  n=n/10;
    		
    	  }
    	  System.out.println(d);
      }
}
      
}

@KUNAL.SHARMA5724510,

double a = 10
When you print a, the output will be 10.0

int a / long a = 10
When you print a, the output will be 10

That’s what giving you the error. The output given in the sample test is the format you have to use while printing. Hence it will not accept double or float. Use long instead of double and incase b =Math.pow(2, i); shows any error, you can cast it to long using b = (long)Math.pow(2, i);

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.