public class For2 { public static void main(String[] args){ int sum = 0; for (int i = 2; i<=100;i++){ if (i%2==0) { sum = sum + i; } } System.out.printf("1+2+3+...+100 = %d",sum); } }
int sum = 0; for(int p = 0; p <= 100 ; p++){ sum = sum + p; } System.out.printf("1+2+3+...+100 = %d%n" ,sum);