Originally Posted by
SaptaZapta
You have this bit:
Code:
c = new int[10];
high = c[0]; //Gives the current "high" value to the first grade entered.
low = c[0]; //Gives the current "low" value to the first grade entered.
You create a new array. It's all zeroes. (I think. Not an expert on Java. It might contain random numbers, which would be worse).
Then you give high and low the value of the first element in the array, which as I just said is 0.
So, both high and low start out as zeros.
Later the loop compares them to the input "grade", but 0 will always be smaller than any grade, so "low" will remain 0.
Oh my god.
You're right, I commented the high and low element lines out and it gave me the right answer. ;__;
Then you have your loop which reads numbers into grade and then adds them into total. Nowhere does it assign "c[counter] = grade;". So c never gets any values. Nor do you use its values anywhere, you only use its length for the loop. Why?
Honestly, I was just going by what my professor's Powerpoint slides showed.
Code:
public class InitArray1 {
public static void main (String [ ] args)
{
int [ ] array ; //declare array named array
array = new int [10]; //creat the array object
System.out.printf("%s%8s\n", "Indexs", "Value"); //column heading
for (int counter = 0; counter <array.length; counter ++) //array.length = 10
System.out.printf("%5d%8d\n",counter, array[counter]);
}
}
Also, I'll be sure to put that debugging tip to use!
Bookmarks