- Jun 13, 2010
- 68
- 0
- 0
I need to pull out single digits out of a number
ex. For number 24362
The output should be:
I do not understand how to do this. My instructor told me to use "/ and %" but the only one I know that is right is my fifth digit below.
Thanks for any help. Either an explanation or a point to the right direction would be great. Thanks!
ex. For number 24362
The output should be:
First Digit: 2
Second Digit: 4
Third Digit: 3
Fourth Digit: 6
Fifth Digit: 2
I do not understand how to do this. My instructor told me to use "/ and %" but the only one I know that is right is my fifth digit below.
Code:
package javahomework;
public class JavaHomework1pt2
{
public static void main( String [] args )
{
int number =24362;
System.out.println("First digit = " + number % 1);
System.out.println("Second digit = " + number % 1);
System.out.println("Third digit = " + number % 1);
System.out.println("Fourth digit = " + number % 1);
System.out.println("Fifth digit = " + number % 10);
Thanks for any help. Either an explanation or a point to the right direction would be great. Thanks!