Question: 1. Binary Representation. Write a program that takes a Positive Integer N (in decimal) from the command line and prints out its binary representation. Recall,
1. Binary Representation. Write a program that takes a Positive Integer N (in decimal) from the command line and prints out its binary representation. Recall, in Program 1.3.7, that we used the method of subtracting out powers of 2. Instead, use the following simpler method: repeatedly divide 2 into N and read the remainders backwards. First, write a while loop to carry out this computation and print the bits in the wrong order. Then use recursion to print out the bits in the correct order.
This is the program you need to modify
public class IntegerToBinary { public static void convert(int n) { if (n == 0) return; convert(n / 2); StdOut.print(n % 2); } public static void main(String[] args) { int n = Integer.parseInt(args[0]); convert(n); StdOut.println(); } } This question is from Introduction to Programming in Java by Robert Sedgewick This is a java program, my IDE is Dr.Java
This is the book website if you need more info, http://introcs.cs.princeton.edu/java/home/
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
