I'm trying to make a java program where the user inputs a decimal number and it it then converted to binary. this is what i have so far but the while loop only loops once and only gives me 0 when i input 8. I know 8 in binary is 1000 so i don't understand what I'm doing wrong. I need the coding to be simple. please help thanks
import java.util.Scanner;
public class binary
{
public static void main (String [] args)
{
Scanner scan = new Scanner(System.in);
int userNum = 0;
int binary = 0;
double newNum = 0;
int count = 0;
System.out.print("Enter a positive base 10 number: ");
userNum = scan.nextInt();
System.out.println();
for(; (Math.pow(2,count) <= userNum); count++)
{
}
while(!(count == 0))
{
if(userNum/Math.pow(2,count) != 0)
{
binary = userNum/(int)Math.pow(2,count);
System.out.print(binary);
}
userNum %= Math.pow(2,count);
count--;
userNum %= (int)Math.pow(2,count));
}
}
}