i'm trying to convert decimal to binary without any arrays or without recursion. I'm aware of the one command that you can use to convert decimal to binary but i'm trying to do this manually. Any help would be appreciated.
public class Decimaltobinary {
public static String decimalToBinary(int valueIn){
// String binaryOut = "";
// int counter = 0;
int remainder, i = 0;
while (valueIn != 0){
remainder = valueIn % 2;
valueIn /= 2;
int binaryNum += remainder * i;
i *= 10;
}
return binaryNum;
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Scanner keyboard = new Scanner (System.in);
System.out.println("Please enter the decimal number: ");
int valueIn = keyboard.nextInt ();
String outputOut = decimalToBinary(valueIn);
System.out.println ("The output is: " +outputOut);
}
}
I'm getting an error for the return BinaryNum statement that says 'cannot find symbol' and an error for the
int binaryNum += remainder * i;
statement. The error says '; expected'.