Advertisement
kalin729

Sum of even in range

Oct 7th, 2021
620
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.40 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Main {
  6.  
  7.     public static void main(String[] args) {
  8.         Scanner scanner = new Scanner(System.in);
  9.         int n = scanner.nextInt();
  10.         int sum = 0;
  11.         for (int i = 0; i <= n; i++) {
  12.             if (i % 2 == 0) {
  13.                 sum += i;
  14.             }
  15.         }
  16.  
  17.         System.out.println(sum);
  18.  
  19.     }
  20.  
  21. }
  22.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement