# Answer to Question #17580 in Java | JSP | JSF for Jeff

Question #17580

how can you strip each digit from a randomly generated number so that it will be displayed as such:

number digits

4028 4 0 2 8

number digits

4028 4 0 2 8

Expert's answer

import java.util.Random;

import java.util.Scanner;

public class Test {

privatestatic Random random = new Random();

staticint generateRandom(int n) {

returnMath.abs(random.nextInt()) % n;

}

publicstatic void main(String[] args) {

intnum = generateRandom(5000);

chardigits[] = String.valueOf(num).toCharArray();

System.out.println("number:" + num);

System.out.println("digits:");

for(int i = 0; i < digits.length; i++) {

System.out.print(digits[i]+ " ");

}

}

}

import java.util.Scanner;

public class Test {

privatestatic Random random = new Random();

staticint generateRandom(int n) {

returnMath.abs(random.nextInt()) % n;

}

publicstatic void main(String[] args) {

intnum = generateRandom(5000);

chardigits[] = String.valueOf(num).toCharArray();

System.out.println("number:" + num);

System.out.println("digits:");

for(int i = 0; i < digits.length; i++) {

System.out.print(digits[i]+ " ");

}

}

}

Need a fast expert's response?

Submit orderand get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

## Comments

Assignment Expert31.10.12, 16:44You're welcome. We are glad to be helpful.

If you really liked our service please press like-button beside answer field. Thank you!

Jeff30.10.12, 20:26Thank you for the help

## Leave a comment