随机数

随机数

代码如下:

package ClassDemo; public class TestRandomCharacter {
public static void main (String[] args) {
final int NUMBER_OF_CHARS = 200;
final int CHARS_PER_LINE =25;

for (int i = 0; i < NUMBER_OF_CHARS; i++) {
char ch = getRandomLetter('A', 'z');
if (0 == (i + 1) % CHARS_PER_LINE) {
System.out.println(ch);
} else {
System.out.print(ch);
}shui
}
} private static char getRandomLetter(char ch1, char ch2) {
return (char) (ch1 + (ch2 - ch1 + 1) * Math.random());
}
}

posted @ 2017-06-20 18:30  辰峰  阅读(161)  评论(0编辑  收藏  举报