import java.util.Scanner; import java.io.IOException; /** * Convert Decimal to Binary * * @author Pam Programmer */ public class DecToBin { /* Driver to get input from standard input */ public static void main(String args[]) throws IOException { Scanner console = new Scanner(System.in); while(console.hasNextLine()) { System.out.println(decToBin(input(console.nextLine()))); } } /** * Handle input and return one valid value. */ public static int input(String input) { // Split the input line into tokens String[] inputs = input.split("\\s+"); int value = 0; // set value to zero value = Integer.parseInt(inputs[0]); /* Convert the string to an integer */ return value; } /** * Determines the binary value of a whole decimal integer. * @pre Valid input * @param value is the decimal value to convert * @returns String binary translation of a whole decimal integer */ public static String decToBin(int value) { String binary = ""; /* Loop */ while(value/2.0 > 0.0) { binary = Integer.toString(value % 2) + binary; value /= 2; } binary = (binary.equals("") ? "0" : binary); return binary; } /** * Determines the number of zeroes in a binary number * @param value is the decimal value to convert * @returns int number of zeroes in the binary equivalent of value */ public static int zeroes(int value) { String binary = decToBin(value); int count = 0; for (int pos = 0; pos < binary.length(); pos++) { char digit = binary.charAt(pos); if (digit == '0') { count++; } } return count; } }