ABaDy1996

ex1 ch4

Oct 3rd, 2020
1,428
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.  
RAW Paste Data