Hi, I'm trying to have a set of random numbers into ArrayList and to print it.
e.g. if the total number is 10, [2,3,5] or [1,5,2,2], etc.
In below, it gives me each numbers but because y gets zero, it throws an exception. Can I have help to print all array elements for below ? tks, naomi
import java.io.*;
import java.util.*;
public class Dice {
public static void main(String[] args) throws FileNotFoundException {
int x;
int y;
x = 0;
y = 50;
x = y - x;
ArrayList<Integer> list = new ArrayList<Integer>();
for (x = x; x > 0; x++) {
Scanner user = new Scanner(System.in);
Random r = new Random();
int roll;
int diff;
roll = r.nextInt(y) + 1;
diff = 0;
for (int n : list) {
x = diff;
}
x = y - roll;
System.out.println(+roll);
System.out.println(+diff);
System.out.println("x=" + x);
System.out.println("y=" + y);
list.add(roll);
if (y>0){
y=x;}
else y=1;
}System.out.println(list);
}
}