fork download
  1. import java.util.*;
  2.  
  3. class MyLabs {
  4. public static void main(String[] args) {
  5. int n = 0, i = 0, s = 0;
  6. System.out.println("Please enter value for N:");
  7.  
  8. Scanner in = new Scanner(System.in);
  9. n = in.nextInt();
  10.  
  11. s = 0;
  12. for(i = 1; i <= n; i++) {
  13. if (i % 2 == 0) {
  14. s = s + i;
  15. System.out.println("Current value i=" + i + " S=" + s);
  16. }
  17. }
  18. System.out.println("Final result suma is S=" + s);
  19. }
  20. }
Success #stdin #stdout 0.14s 58888KB
stdin
1
2
10
42
11
stdout
Please enter value for N:
Final result suma is S=0