Advertisement
ABaDy1996

ex1 ch4

Oct 3rd, 2020
1,618
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.40 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class ch4ex1 {
  4.     public static void main(String[] args){
  5.         Scanner in = new Scanner(System.in);
  6.         int n, sum=0,i=0;
  7.         System.out.print("Enter the number: ");
  8.         n = in.nextInt();
  9.         while(i<=n){
  10.             if(i % 2 == 0) sum += i;
  11.             i++;
  12.         }
  13.         System.out.printf("The sum of even numbers is %d",sum);
  14.     }
  15. }
  16.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement