Guest User

Untitled

a guest
Nov 13th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. public static void main(String[] args)
  2. {
  3. int limit = 0;
  4. int sum = 0;
  5.  
  6. Scanner scan = new Scanner(System.in);
  7.  
  8. System.out.print("Enter Limit: ");
  9. limit = scan.nextInt();
  10.  
  11. System.out.println();
  12. System.out.println("Sum of the even numbers between 2 and " + limit + " (inclusive) are:");
  13.  
  14. for (int count = 1; count <= limit; count++)
  15. {
  16. // Needed if ever even
  17.  
  18. if((count & 1)!= 1)
  19. {
  20. sum+=count;
  21. System.out.println(count);
  22. }
  23. }
  24. System.out.println("Total sum is " + sum);
  25.  
  26. }`
Add Comment
Please, Sign In to add comment