it gives me a arithmeticException on this line System.out.println("\nTotal = " + dSum + " - Average " + (dSum/divider) );
import java.util.*;
public class Lab1A{
public static void main(String [] args){
Scanner input = new Scanner (System.in);
int [] k = new int [20];
int [] d = new int [20];
String option= " ";
for (int i=0; i<25; i++ ){
double random = Math.random();
int x = (int) (random*100);
int y = (int)x + 1; //Add 1 to change the range to 1 - 100 instead of 0 - 99
System.out.print("Random Number: ");
System.out.print(y);
System.out.println("\nEnter Option: (K, D, Q): ");
option =input.next();
if ( option.equalsIgnoreCase("K") ){
k[i] = x;
}
else if (option.equalsIgnoreCase("D")){
d[i] = x;
}
else if (option.equalsIgnoreCase("Q")){
break;
}
} int dSum = 0;
int kSum = 0;
int dAvg = 0;
int kAvg = 0;
int divider = 0;
System.out.print(" You discarded: \n" );
if(d[0] != 0){
for (int discard = 0; discard< d.length -1; discard++){
if (d[discard] != 0){
System.out.print(d[discard] + " ");
dSum += d[discard];
divider ++;
}
else
break;
}
}
System.out.println("\nTotal = " + dSum + " - Average " + (dSum/divider) );
divider = 0;
System.out.print(" You kept: \n" );
if(k[0] != 0){
for (int keep = 0; keep< k.length -1; keep++){
if (k[keep] != 0){
System.out.print(k[keep] + " ");
kSum += k[keep];
divider++;
}
else
break;
}
}
System.out.println("\nTotal = " + kSum + " - Average " + (kSum/divider) );
}
}