- 1

Java question [guys help me solve this question.]

Write a program to convert numbers. The user should be able to select from a menu option and enter the number to convert. The program must do the conversion and display output. After that, the program must ask if the user wants to perform another conversion without exiting 1. Decimal to Binary 2. Binary to Decimal 2. Write a program to sum the digits in an integer. (use % and / operators) e.g. 1234 = 10

21st Apr 2022, 12:17 AM
Gabriel Walim
Gabriel Walim - avatar
2 Answers
+ 2
Display menu Input user's choice If choice is one Call decimal to binary function else if choice is two Call binary to decimal function else Display error message or exit Decimal to binary function Display prompt Read decimal string Verify the string characters are valid If not Display error message Else Convert string to integer (parseInt) String initialized to empty While integer is not zero String becomes new digit (integer%2) as character plus old string Integer becomes old integer without digit (integer/2) If string is empty Display zero Else Display string Binary to decimal function Display prompt Read binary string Verify the string characters are valid If not Display error message Else Zero decimal number For each character in binary string If character is one Add one to decimal Multiply decimal by two Display decimal
21st Apr 2022, 12:43 AM
John Wells
John Wells - avatar
- 1
Thanks but I ne need it in a Java solution
21st Apr 2022, 1:07 AM
Gabriel Walim
Gabriel Walim - avatar