很简单,我只想要一个代码(而不是在控制台中打印出单独的文本行)只用新值更新一行文本,或者“替换”它。
当前代码:
//this code was expanded into a more configurable version
//original author is zengr
public final class EnumRandValue {
public static final void main(String... aArgs){
int min = 12;
int max = 157;
int ints = 1000;
//how many numbers to generate?
int enumeration = 1;
int maximumints = 1000;
//advanced users only!
log("Generating " + ints + " random integers in range of " + (min-1) + " and " + (max-1) + ".");
//note a single Random object is reused here
if(min < max || min != max) {
Random randomGenerator = new Random();
for (int idx = 1; idx <= ints; ++idx){
int randomInt = randomGenerator.nextInt(max);
log("E" + enumeration++ + ": " + randomInt);
if(enumeration >= maximumints) {
String breakmsg = "Exceeded enums limit (" + maximumints + ").";
log(breakmsg);
return;
} else if(min >= max) {
String breakmsg = "Invalid min/max values.";
log(breakmsg);
return;
} else {
//really nothing happens here
//some code was excluded
答案 0 :(得分:0)
我假设你的log()方法是一个静态方法,它打印传递给它的字符串。
在这种情况下,如果您只想打印for循环的最后一行,请在打印前检查以下条件。
if(idx==ints)
log("E" + enumeration++ + ": " + randomInt);