Little hint: declare variable as late as possible, better if in the same moment when you initialize/use them the first time.
Originally posted by shazar kv:
short num = 0;
Scanner keyboard=new Scanner (System.in);
System.out.println("Number?");
num=keyboard.nextShort();
would be better written this way:
In the following case, always taken from you code, it's ok to declare a variable a bit before is it used because of a problem of
scopes
Originally posted by shazar kv:
String bi = "";
while(num>=1)
{
if(num%2==0)
bi="0";
if(num%2==1)
bi="1";
num/=2;
}
System.out.println(bi);
And now..a question: what you are tryng to do with this program is printing the binary representation of the user-digited number?