How to add the current iteration's value to the previous iteration's value
in a loop
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);
}
}
I want to add the number that was given in the previous iteration to the
number in the current iteration of the loop.
Basically I want new n to be equal to old random number + new random number.
No comments:
Post a Comment