Write a program that converts a number from binary to decimal. Prompt the user for a binary number and display the decimal number. Include a loop that prompts the user “Do you wish to continue?”, so that the user can run the program more than once. Use integer division and modulus

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter7: Characters, Strings, And The Stringbuilder
Section: Chapter Questions
Problem 9PE
icon
Related questions
Question

Write a program that converts a number from binary to decimal.  Prompt the user for a binary number and display the decimal number. Include a loop that prompts the user “Do you wish to continue?”,  so that the user can run the program more than once. Use integer division and modulus. Do NOT use any String methods.

Sample run.

Enter a binary number.

1111

1111 in binary is 15 in decimal

 

Do you want to continue(Y or N)?

Y

Enter a binary number.

1010

1111 in binary is 10 in decimal

 

Do you want to continue(Y or N)?

N

Program Terminated

 

Consider using the following algorithm.


Use a loop to do the following tasks. Isolate each digit from the rightmost digit to the leftmost digit.  For each digit, calculator the sum of the products of the digit * 2n, where n is a power of 2.

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT