Having a problem converting loop output into an array. I am converting a decimal into binary form but I want it to print out from left to right rather than in a vertical line. I assume there is a way to add the loop output into an array 1 by 1.
My code snipet from the program:
if (choice == 2)//convert decimal to binary
{
System.out.println("Enter a decimal digit between -512 and 511 to convert to binary.");
decimal = keyboard.nextInt();
decimal2 = decimal;
while(decimal > 0){
decimal2 = decimal % 2;
decimal = decimal /2;
System.out.println(decimal2);
}
}
Thanks for any help!
You can use a string to concatenate the remainder values.
inside the loop
outside the loop you print: