How to print a list of even numbers in Java

1 Answer

0 votes
package javaapplication1;

public class JavaApplication1 {

    public static void main(String[] args) {

         int n = 35;

        for (int i = 1; i <= n; i++) {
            if (i % 2 == 0) {
                System.out.print(i + " ");
            }
        }
    }
}
 
/*

run:

2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 

*/

 



answered Oct 13, 2016 by avibootz
...