[Help me Plz] Decimal to Binary
//My Problem on this is i need the output to be reversed
//Example Run:
//Enter a decimal number
//100
//The Decimal Number is: 100
//Its Binary Representation is:
//0010011
//I need the output to be reversed to 1100100
//Without using the .reverse or .IntegerToBinary methods
//Any help would be appreciated
import java.lang.*;
import java.util.*;
public class BinaryDecimal
{
public static void main(String[ ] args)
{
Scanner keyBoard = new Scanner(System.in);
System.out.println("Enter a decimal number");
int num = keyBoard.nextInt();
System.out.println("The Decimal Number is: " + num);
System.out.println("Its Binary Representation is:");
while(num != 0)
{
int numHold = num / 2;
if (num % 2 == 0)
{
System.out.printf("0");
}
else
{
System.out.printf("1");
}
num = numHold;
}
}
}
Re: [Help me Plz] Decimal to Binary and "Printing Stars"
We're not going to write it for you, so what, exactly, is the difficulty you have with writing this code?
The biggest difference between time and space is that you can't reuse time...
M. Furst
Re: [Help me Plz] Decimal to Binary and "Printing Stars"
See if you can find an apropriate method in the Integer class.
Laitinen