I am new to the java world and I am currently taking a Programming I class. My homework assignment for the week is to write a java program using methods to allow a user to enter in a decimal number(base 10) and have the program convert it to a binary number. Just remember I am new to this so I don't know everything. I need some input on how finish finish the program I have wrote. It compiles, runs, but only allows the user to enter in a decimal number. It won't convert it. Can someone please help me with what I am doing wrong?
Here is what I have so far:
import java.util.Scanner;
public class Decimal{
public static void main (String [] args){
Scanner input = new Scanner(System.in);
System.out.println ("Enter a decimal number: ");
int decimal = input.nextInt ();
System.out.println ("Binary number is: " + decimalToBinary(decimal));
}
public static String decimalToBinary(int decimal) {
int i = 42;
String decimalToBinary = Integer.toBinaryString(i);
while (decimal !=0){
int binaryValue = decimal % 16;
decimal = decimal/16;
}
return decimalToBinary;
}
}