Does it have to be a while loop? Typically, when the programmer can identify positively how many times the loop must execute, either a for or enhanced for loop would be used. Here are the Java tutorials on looping.
Learning Java using Eclipse on OpenSUSE 11.2
Linux user#: 501795
raul vargas wrote:
Yes, it has to be a while-loop. Those are the only loops I can work with.
I don't know how to initialize to -1.0
The example loop I have looks like this:
if it must, it must...
you are missing part of the while loop. Generally, they look like this:
Those braces are important. You need a closing one for each opening one, and your example is missing the closing one.
So you have the line "int i = 0;". That is just there to set up the starting conditions.
You then have "while (i < 10)". Each time through the loop, that condition is checked. So hopefully, i will be changing inside your loop, otherwise you will be stuck in there forever - what is called an "infinite loop".
So you need to put code inside the curly brackets - what is called the body of the loop. You have "i++" in the loop. Each time that line executes, i will be incremented by 1. so the first time, it will change from 0 to 1, then from 1 to 2, etc. That means that this loop will run ten times before quitting. That is convenient, since you have an array with ten elements. The common idiom is to use your variable i as an index (that's why i is often used as the variable name) of the array.
To access a specific element of the array, you say "arrayName[index]". In your example, you have one array called quizzes. you set a value the same way as any other double variable. If i had a double named "fred", i would say
fred = 1.0;
since i have an array, i can say
this.quizzes = 1.0;
that would set the fourth element to 1.0 (remember, arrays are zero based indexed, so the first element is this.quizzes).
So you could explicitly name all ten elements and set each to -1: