【发布时间】:2017-09-16 11:38:45
【问题描述】:
这个程序是随机生成 100 个 4 字母数字,它首先生成 4 个字母,然后再生成 4 个并将它们添加到函数中。我猜这是因为我使用了.append。我尝试输入 random = "";在循环的顶部和底部,但它只是清除了变量。有没有其他方法可以做到这一点,或者有什么可以添加到程序中的吗?
Random input = new Random();
StringBuilder in = new StringBuilder();
String alphabet = "abcdefghijklomnpqrstuvwxyz";
char[] letterPool;
letterPool = alphabet.toCharArray();
for(int y = 0; y < 101; y++){
for(int x = 0; x<4; x++){
in.append(alphabet.charAt(input.nextInt(alphabet.length())));
}
String random=in.toString();
System.out.println(random);
System.out.println("space");
}
【问题讨论】:
-
嗯??