public class Recount {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Random rand = new Random();
boolean s = false;
int a;
Scanner quest = new Scanner(System.in);
do {
int n = rand.nextInt(100) + 1;
System.out.println(n);
System.out.println("Try again?");
s = quest.nextBoolean();
} while (s != false);
}
}
Run Code Online (Sandbox Code Playgroud)
我想将上一次迭代中给出的数字添加到循环当前迭代中的数字中。
基本上我希望新 n 等于旧随机数 + 新随机数。