Answer to Question #17578 in Java | JSP | JSF for Jake

Question #17578
How do you strip each digit from a randomly generated number and store it and display?
1
Expert's answer
2012-10-30T12:51:06-0400
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]+ " ");
}
}

}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS