davey
02-03-2005, 07:43 PM
public static int total(int[] cards){
int total=0;
for(int i=cards.length; i>0; i--){
total+=cards[i];
}
return total;
}
public static void main(String[] args) {
int[] dealerhand = new int[21];
dealerhand[1]=dealcard();
dealerhand[2]=dealcard();
dealerhand[0]=total(dealerhand);
}
i want to do this but it says
java.lang.ArrayIndexOutOfBoundsException: 21
this error occurs in the method and i believe i need to set cards to be 21 spaces but i dont know how
can you help me?
int total=0;
for(int i=cards.length; i>0; i--){
total+=cards[i];
}
return total;
}
public static void main(String[] args) {
int[] dealerhand = new int[21];
dealerhand[1]=dealcard();
dealerhand[2]=dealcard();
dealerhand[0]=total(dealerhand);
}
i want to do this but it says
java.lang.ArrayIndexOutOfBoundsException: 21
this error occurs in the method and i believe i need to set cards to be 21 spaces but i dont know how
can you help me?