Saturday, December 17, 2011

I have a java code problem, can someone HELP?

ok, so i had to do a project of converting binary to decimal numbers, i think i made the right code but the compiler gives me an error





import javax.swing.JOptionPane;





public class BtoD


{


public static void main(String []args)


{


String testNum = JOptionPane.showInputDialog("Enter Bianry Number");


int x = testNum.length();


int[] binary= new int [x];


for(int i=0;i%26lt;x;i++)


{


binary[i]=Integer.parseInt(testNum.鈥?br>

}


int decimalNum=0;


int y=1;


for(int i=x-1;i%26gt;=0; i--);


{


decimalNum=decimalNum+(binary[i]*y)鈥?br>

y=2*y;


}


String output=" your decimal number is" + decimalNum;


JOptionPane.showMessageDialog(null,o鈥?br>

}


}





the error it gives me is: cannot find symbol


symbol : variable i


location: class BtoD


decimalNum=decimalNum+(binary[i]*y)鈥?br>




please someone help?!








|||This is a good one, took me a minute to spot the error. The problem is in this line:





for(int i=x-1;i%26gt;=0; i--);





The semi-colon at the end, ends the line so the code within the curly braces is not part of the if statement so doesn't have access to i.

No comments:

Post a Comment