In Java, I made an int array, and I want to add several of those values together to get another value in that same array, but I'm (understandably) getting an error message that says "variable might not have been initialized." Here is the code:
public static void random(){
Random rand = new Random();
int[] colours = {rand.nextInt(20)+1,rand.nextInt(20)+1,(100-(colours[0]+colours[1]))};
What I want to have happen, here, is for the first element of "rand.nextInt(20)+1" (let's call it "value A") to be added to (what we'll call) value B to get value C (the "100-colours[0]+colours[1]"). I want (100-A+B)=C for my third value. Is there any way I can do this while keeping value C in the array? I'm going to be putting these values through a for loop, and I want each value to correspond with the number of loops (basically, I want one value put out with each loop; loop 1 outputs A, loop 2 outputs B, loop 3 outputs C).