Am I using correct programming principles?

Hello!

I'm currently working on the first few problems from projecteuler.net, so that I can learn Java 'by doing' as well as reading.

Problem 2 is:

Quote:

Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:

1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...

Find the sum of all the even-valued terms in the sequence which do not exceed four million.

My code:

Code:

`public class ProblemSet {`

public static void main(String[] args) {

int fibminus2 = 1;

int fibminus1 = 2;

int newno = 0;

int total = 2;

while(newno < 4000000){

newno = fibminus1+fibminus2;

if(newno % 2 == 0){

total+=newno;

}

fibminus2 = fibminus1;

fibminus1 = newno;

}

System.out.println(total);

}

}

In case you didn't understand my variable naming, fibminus2 + fibminus1 will give you the next number in the sequence (newno).

I've been able to solve this problem, but the thing I would like to get feedback on is whether I wrote this in a 'correct' and 'efficient' way. I know this request is a little vague, and for that I'm sorry. I want to learn good programming principles from the very start. ;)

There is a thread on the Project Euler website where people can share their solutions. There are quite a few Java ones, but I can't really tell which ones use good principles and which one use bad/inefficient ones.

One question I have in particular is whether I should be using the while loop, like I did in my code, or whether I should be using the for loop (like this: for(int i = 0, i < 4000000, i++))

I'd very much appreciate help in any form!

Beefy