You could write a PhD thesis in philosophy on Evangelion. I didn't have the patience to even try to figure it out.
This sounds like a job for a "for" loop. But if you want to do it with a while loop, that's fine too.
As I understand, you want to find the sum of 'n' odd integers.
Ok, if that's the case, you want to loop 'n' number of times. You'll need two variables, one to keep the sum and one to keep track of the loop. Here's a sample method:
Code:
public int oddSum(int n){
int sum = 0;
int i = 0;
while(i < n){
// <Enter odd-summing code here.>
i++; // This will increase the value of 'i' by one. It's a common programming shortcut.
}
return sum;
} The loop breaks when 'i' equals 'n'. Why not when 'i' greater than 'n'? Because in programming, all things start at '0' instead of '1'. Chalk it up to tradition, but it's going to be a recurring theme in programming.
If someone wants to the sum of the first odd number, they'll enter '1'. Well, because 0 is less than 1, the loop will execute. Next time around, 'i' will equal 1, and therefore not be less than 'n', and the loop will break before executing the code again.