Hi all,

I have this problem: Transform a Decimal to a Binary.

So, i did this:

-------------------------------------------------------------------------------------------------------------------------------------------------------------

public static void main(String[] args) throws IOException {

int NumDec;

int R;

System.out.println("Decimal");

do

{

BufferedReader input = new BufferedReader ( new InputStreamReader (System.in));

String line = input.readLine();

NumDec = Integer.parseInt (line) ;

}

while((NumDec <= 0) || (NumDec != NumDec));

String NumBin = "";

BufferedReader input = new BufferedReader ( new InputStreamReader (System.in));

while(NumDec != 0)

{

NumDec = NumDec/2;

R = NumDec%2;

NumBin = NumBin+R;

}

System.out.println("Binary: "+NumBin);

}

}

-------------------------------------------------------------------------------------------------------------------------------------------------------------

Well, the problem is ouput.

-------------------------------------------------------------------------------------------------------------------------------------------------------------

Decimal

2

Binary: 10

Decimal

8

Binary: 0010

Decimal

9

Binary: 0010

Decimal

55

Binary: 110110

...so on...

-------------------------------------------------------------------------------------------------------------------------------------------------------------

Can you help me?