here is my code
private static void stats(String[] args) {
if (args.length == 1) {
System.out.print("Error: Argument count mismatch");
return;
}
int[] array = {0};
double average = 0.0;
int total = 0;
int count = 0;
int max = array[0];
int min = max;
for (int i = 1;i < args.length;i++) {
if (isInteger(args[i]) == false) {
System.out.print("Error: Argument type mismatch");
return;
}
else {
count++;
int a = Integer.parseInt(args[i]);
total += a;
average = total / count;
max = a;
for (int d = 1; d < array.length; d++) {
if (array[d] > max) {
max = array[d];
}
if (array[d] < min) { // change to > for largest
min = array[d];
}
}
}
}
System.out.println("Total " + total);
System.out.println("Max " + max);
System.out.println("Min " + min);
System.out.printf("Average " + "%.2f
" , average);
}
for some reason it won't print out the max and min values, I tried a couple of things and my idea is that I might need to declare max and min again, but to what?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…