0

Write an application that inputs one number consisting of FIVE digits from the user, separates the number into its individual digits and prints the digits separated from one another by three spaces each. For example, if the user types in the number 12345, the program should print

1   2   3   4   5

The following screen dump of result is for your reference.

Input a digit: 12345
Digits in 12345 = 1 2 3 4 5

How to convert binary, OCT, HEX to calculate the question?

int digit1, digit2, digit3, digit4, digit5;
digit1 = number / 10000;
digit2 = number % 10000 / 1000;
digit3 = number % 1000 / 100;
digit4 = number % 100 / 10;
digit5 = number % 10;
4
  • please explain what you mean by 'How to convert binary, OCT, HEX to calculate the Question' - that has no relation to the rest of your post
    – chris
    Apr 14, 2010 at 17:14
  • 1
    Hi, welcome at Stackoverflow! For future homework/interview assignments, please tag homework as well. Oh, please also use one question mark ? instead of a bunch of exclamation marks !!!!!!!!! to represent a question, otherwise it's been interpreted as yelling/jerking.
    – BalusC
    Apr 14, 2010 at 17:15
  • 1
    @Roman: There are more as well...
    – BalusC
    Apr 14, 2010 at 17:17

1 Answer 1

1

You can make use of the methods the java.lang.Integer class provides, such as toBinaryString(), toOctalString() and toHexString() and the toString() and valueOf() methods taking a radix (which is the base, e.g. binary is 2, octal is 8, etc).

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.