Question: Chapter 5 Problem 37 (Decimal to Binary) Write a program that prompts the user to enter a decimal integer and displays its corresponding binary value.
Chapter 5 Problem 37 (Decimal to Binary)
Write a program that prompts the user to enter a decimal integer and displays its corresponding binary value. Don't use Java's Integer. toBinaryString(int) in this program. Hint: Program Plan. 1) Enter a decimal integer number. Do NOT use
public static StringBuffer toBinary(int number) { StringBuffer sb = new StringBuffer(); int t=0; while(number>0) { t = number%2; sb.append(t); number = number / 2; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
