tags:

views:

76

answers:

1

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;
+1  A: 

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).

BalusC
thanks! i will try it.