Java examples for Language Basics:for
Summing integers with the for statement.
public class Main { public static void main(String[] args) {// ww w. jav a 2 s. c om int total = 0; // total even integers from 2 through 20 for (int number = 2; number <= 20; number += 2) total += number; System.out.printf("Sum is %d%n", total); } }