The Binary code is not working

this code is not working

import java.util.Scanner;
import java.lang.Math ;
public class Main {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
int[] bn = new int [num] ;
for(int j=0;j<num;j++)
{
bn[j] = sc.nextInt();
}
for(int j=0;j<num ;j++)
{ int tmp1,tmp2;
int dn=0 , rem=0 ; // rem for remainder
int n = (int)Math.log10(bn[j]) + 1 ;
if(bn[j]<0)
{
System.out.println(“False”);
continue;
}
if(bn[j]>0)
{ for(int k=0 ; k<n;k++)
{ tmp1 = bn[j];
tmp2 = tmp1 % 10;
tmp1 = tmp1 /10;}
if(!(tmp2==0||tmp2==1))
{
System.out.println(“False”);
continue;
}
else
{
for(int i = 0; i<n;i++)
{
rem = bn[j] % 10;
dn += Math.pow(2,i)*rem;
bn[j] = bn[j] / 10 ;
}
System.out.println(dn);
} }}
}
}

Is an array required or 4 justs represents the number of inputs given in the question

your code is working fine.just initailise temp1 and temp2 to 0.

4 is the no. Of inputs but your code is running for array…

So i have to deal with one input at a time??

yeah bro…run loop 4 times and deal with input at once

But n (or 4 in this case) will be given by the user according to question.

yeah so take n and run a loop n times in which you are taking a input to get the output
so your code look like this.
int n=user_input;
while(n!=0){
int x=user_binaryinput;
//your work and output
n–;
}

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.