Program to change base system, JAVA Programming

Write a program called BaseConverter that prompts (asks) the user for a base 10 number and another number, between 2 and 10 inclusive. This second number is the base to which to convert the first number. The program outputs the original number and the number converted to the given base. If the base number is less than 2 or greater than 10, the program outputs a message and terminates.

Note: this problem is to be solved using only the Scanner, String and System classes. Arrays or other data structures are not allowed.

System.exit( ) is not be used anywhere in any of the Tasks, marks will be deducted if it is used anywhere in this assignment.

The algorithm for this conversion is to keep dividing the base 10 number by the conversion base, recording the remainders, until the base 10 number is 0. Then write the result, starting from the bottom and work up to the top.

> java BaseConverter
Enter decimal number >> 153
Enter base to convert to >> 8
153 in base 10 converted to base 8 is 231
 
java BaseConverter
Enter decimal number >> 153
Enter base to convert to >> 7
153 in base 10 converted to base 7 is 306
 
> java BaseConverter
Enter decimal number >> 153
Enter base to convert to >> 5
153 in base 10 converted to base 5 is 1103
 
> java BaseConverter
Enter decimal number >> 153
Enter base to convert to >> 2
153 in base 10 converted to base 2 is 10011001
 
> java BaseConverter
Enter decimal number >> 153
Enter base to convert to >> 10
153 in base 10 converted to base 10 is 153

> java BaseConverter
Enter decimal number >> 153
Enter base to convert to >> 16
Conversion base must between 2 and 10 inclusive

Posted Date: 2/16/2013 5:36:55 AM | Location : United States







Related Discussions:- Program to change base system, Assignment Help, Ask Question on Program to change base system, Get Answer, Expert's Help, Program to change base system Discussions

Write discussion on Program to change base system
Your posts are moderated
Related Questions
Draw a 5 inch square on the screen using pseudocode

What is virtual function? While derived class overrides the base class method by redefining the same function, after that if client wants to access redefined the method from der


JMS consumer is a JMS client that receives messages.

1.) Write an application with two user transactions (login which includes viewAllStudents and viewStudent ) with full MVC architecture that displays the details of the selected

I want FitLIFE app for Android, IOS, Windows Project Description: Hello, I want to develop an app for Android, IOS and Windows Phone. This app will be work with open source B

Describe the java.lang package ? Each package describes a number of classes, exceptions, interfaces, and errors. For instance, in Java 1.1 the java.lang package holds these:

1. Write the pseudocode to get the input of 10 integers from the user and add them up and output the total. (4 points) 2. Compute the output of following pseudocode. Assume that

Problem 1 A savings account object holds a non-negative balance, and provides deposit(k ) and withdraw(k ) methods, where deposit(k ) adds k to the balance, and withdraw(k ) subtra

What Can an Applet Do? An applet can: • Draw pictures on a web page • Create a new window and draw in it. • Play sounds. • Receive input from the user by the keyboard or