ITEC 120 LAB 6 Back to Lab index page

Loop de loop

You will write Java program that will ask the user to enter a positive even number. (If the user does not enter a positive even number, the program will continue to ask the user until they do.) Once a positive even integer is entered, your program will add it to a running total, and print it and the running total to the screen. Your program will continue to add input numbers together as long as they are positive even numbers. As soon as a non-even or non-positive number (odd, negative, or 0) is entered, the program quits.

Sample run

Program outputs:

Please enter a positive even integer:

User inputs: 0
Program outputs:

Please enter a positive even integer:

User inputs: -6
Program outputs: Please enter a positive even integer:
User inputs: 4
Program outputs:

4 is even. The sum so far is: 4
Please enter a positive even integer:

User inputs: 8
Program outputs: 8 is even. The sum so far is: 12
Please enter a positive even integer:
User inputs: 7
Program outputs: Thanks for using the amazing loop de loop program. Goodbye.

You will use the Keyboard class for this assignment. Make sure the Keyboard.class file is in a folder called cs1 in the same directory as your .java file. You will use loops for this assignment. Use incremental development to write this program. First, write a loop that will verify that the user has entered a positive even number. Once you have that running and tested, write the loop that adds the even numbers.

Once you have your program working, show your lab to the Peer Instructor to be checked off. The Peer Instructor will run the program.