简体   繁体   English

如何在一行而不是多个中更新?

[英]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.

相关问题 如何查找多个年份而不只是一个年份的复活节日期? - How to find easter dates for multiple years rather than just one? 在一行中记录多个事物而不是记录多行有什么好处? - Any advantage of logging multiple things in one line rather than logging multiple lines? RecyclerView 只显示一张图片而不是多张图片 - RecyclerView only shows one image rather than multiple JavaFX需要多个ImageView节点而不是一个引用? - JavaFX requires multiple ImageView nodes rather than a reference to one? 多次初始化一个变量而不是重新分配一个变量是否效率低下? - Is it inefficient to initialize a variable multiple times rather than reassigning one? 如何使用Maven一项而不是一项并行运行测试? - How to run test one by one rather than parallel using maven? 如何在一行中替换多个字符串? - How to replace more than a string in one line? 读取此文件而不是创建一个新文件? - Reading this file rather than creating a new one? 如何让类变量文件检查打印行而不是抛出异常 - How to get class variable file check to print line rather than throw exception 如何“更新”现有的命名实体识别模型 - 而不是从头开始创建? - How to “update” an existing Named Entity Recognition model - rather than creating from scratch?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM