how would i keep adding a random integer to the end of an arraylist? the amount of random numbers to be added is not set

Recommended Answers

All 4 Replies

Use a while loop:

while (true) {
  ....
}

Keep reading input from the keyboard. When, for example, you enter "quit", exit from the loop using the "break" command. Else convert that input into a number and add it to the list.

String input;
while (true) {
  // read input
  if ("quit".equals(input)) {
     break;
  } 
  // convert it into a number and add it to the list
}

i get what your saying but i don't think i explained it well sorry
what i meant was how do i keep adding the results of a die roll to the end of an arraylist without a set amount of rolls

What do you mean "without a set amount of rolls" ?
You roll the dice and add it to the list. Then you roll it add it again.
But you have to stop eventually.

The program will eventually crash with an OutOfMemoryError. Should be a good enough end :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.