Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class ch4ex1 {
- public static void main(String[] args){
- Scanner in = new Scanner(System.in);
- int n, sum=0,i=0;
- System.out.print("Enter the number: ");
- n = in.nextInt();
- while(i<=n){
- if(i % 2 == 0) sum += i;
- i++;
- }
- System.out.printf("The sum of even numbers is %d",sum);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement