Advertisement
StefanTobler

Lesson 17 Activity 2

Oct 13th, 2016
834
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.00 KB | None | 0 0
  1. /*
  2.  * Lesson 17 Coding Activity 2
  3.  * Ask the user for two numbers. Print only the even numbers between them,
  4.  * you should also print the two numbers if they are even.
  5.  *
  6.  *     Sample Run 1:
  7.  *        
  8.  *         Enter two numbers:
  9.  *         3
  10.  *         11
  11.  *        
  12.  *         4 6 8 10
  13.  *
  14.  *    Sample Run 2:
  15.  *        
  16.  *         Enter two numbers:
  17.  *         10
  18.  *         44
  19.  *        
  20.  *         10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44        
  21.  *
  22.  *
  23.  */
  24.  
  25. import java.util.Scanner;
  26. import java.lang.Math;
  27.  
  28. class Lesson_17_Activity_Two {
  29.     public static void main(String[] args)
  30.      {
  31.       Scanner scan = new Scanner (System.in);
  32.       int x;
  33.       int y;
  34.       System.out.println("Enter two numbers:");
  35.       x = scan.nextInt();
  36.       y = scan.nextInt();
  37.       while (x <= y)
  38.       {
  39.         if (x%2 == 1)
  40.         {
  41.          x++;
  42.         }
  43.         else
  44.         {
  45.          System.out.print(x + " ");
  46.            x++;
  47.         }
  48.       }
  49. }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement