fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4.  
  5. class MyLabs
  6. {
  7. public static void main (String[] args) throws java.lang.Exception
  8. {
  9. var n = 0;
  10. var i = 0;
  11. var s = 0;
  12.  
  13. System.out.println("Please enter value for N\n");
  14. Scanner in = new Scanner(System.in);
  15. n = in.nextInt();
  16. in.close();
  17.  
  18. s = 0;
  19. for (i = 1; i <= n; i += 1)
  20. {
  21. if (i % 2 == 0)
  22. {
  23. s = s + i;
  24. System.out.println("Current value i=" + i + " S=" + s + "\n");
  25. }
  26. }
  27. System.out.println("Final result suma is S=" + s);
  28. }
  29. }
Success #stdin #stdout 0.2s 60612KB
stdin
15
stdout
Please enter value for N

Current value i=2 S=2

Current value i=4 S=6

Current value i=6 S=12

Current value i=8 S=20

Current value i=10 S=30

Current value i=12 S=42

Current value i=14 S=56

Final result suma is S=56