[英]How to update in one line rather than multiple?
Simple, I just want a code that (instead of printing out individual lines of text in the console) update just one line of text with the new values, or "replace" it. 很简单,我只需要一个代码(而不是在控制台中打印出单独的文本行),用新值来更新一行文本,或者“替换”它。
Current Code: 当前代码:
//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
I'm assuming that your log() method is a static method that prints the string that is passed to it. 我假设您的log()方法是一个静态方法,它打印传递给它的字符串。
In that case if you just want to print the last line of your for loop check the below condition before your print. 在这种情况下,如果您只想打印for循环的最后一行,请在打印之前检查以下情况。
if(idx==ints)
log("E" + enumeration++ + ": " + randomInt);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.