Advertisement
Guest User

Untitled

a guest
Mar 4th, 2015
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.91 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class WhileLoops
  4. {
  5.     public static void main(String[] args)
  6.     {
  7.     Scanner input = new Scanner(System.in);
  8.  
  9.     System.out.println("Enter an integer: ");
  10.     int firstNum = input.nextInt();
  11.     System.out.println("Enter another integer that is larger than the first one: ");
  12.     int secondNum = input.nextInt();
  13.    
  14.     int sumOne = 0;
  15.     int sumTwo = 0;
  16.    
  17.     System.out.print("Even Numbers:");
  18.         while (firstNum <= secondNum)
  19.         {
  20.             if (firstNum % 2 == 0)
  21.             {
  22.                 System.out.print(" " + firstNum);
  23.             }
  24.             firstNum++;
  25.         }
  26.        
  27.     System.out.print("\nOdd Numbers:");
  28.         while(firstNum <= secondNum)
  29.         {
  30.             if (firstNum % 2 != 0)
  31.             {
  32.                 System.out.print(" " + firstNum);
  33.             }
  34.             firstNum++;
  35.         }
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement