Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class WhileLoops
- {
- public static void main(String[] args)
- {
- Scanner input = new Scanner(System.in);
- System.out.println("Enter an integer: ");
- int firstNum = input.nextInt();
- System.out.println("Enter another integer that is larger than the first one: ");
- int secondNum = input.nextInt();
- int sumOne = 0;
- int sumTwo = 0;
- System.out.print("Even Numbers:");
- while (firstNum <= secondNum)
- {
- if (firstNum % 2 == 0)
- {
- System.out.print(" " + firstNum);
- }
- firstNum++;
- }
- System.out.print("\nOdd Numbers:");
- while(firstNum <= secondNum)
- {
- if (firstNum % 2 != 0)
- {
- System.out.print(" " + firstNum);
- }
- firstNum++;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement