i am trying to work with arrays where each element is a random number. it has 3 elements and i need to remove the lowest value, and come up with 2 elements. after this i add the two elements together. Here is the code i am trying to compile.
int D6;
Random rnum = new Random();
int[] abilityScore = {rnum.nextInt(6) + 1, rnum.nextInt(6) + 1, rnum.nextInt(6) + 1};
int roll = 0;
int min = abilityScore[0];
for(int u = 0; u < abilityScore.length ; ++u){
if(min < abilityScore[u]){
min = abilityScore[u];
}
}
for(int o = 0 ; o < abilityScore.length ; ++o){
if(min == abilityScore[o]){
for(int i = 0 ; i < abilityScore.length ; ++i){
abilityScore[i] = abilityScore[i + 1];
}
}
}
for(int x = 0 ; x < abilityScore.length ; ++x){
roll += abilityScore[x];
}
I am getting an out of bounds exception, which does make sense but i'm not sure how else to make this change. information on how else to do this or how i can tweak this to make it work would be great. Thanks!