ITEC 120 Back to Assignment index page
   
Assignment 1 - Even and odd adder
Submit your program to your folder on neelix.

Description:  Write a program which gets a positive integer number from the user and calculates the sum of all the even integers between 1 and that number, the sum of all the odd integers between 1 and that number, and tells which sum is larger.

Using the Keyboard class, get a positive integer from the user. Give the user an error message if the integer is 0 or less. Calculate the sum of all the even integers between 1 and the number they entered. Output that value. Calculate the sum of all the odd integers between 1 and the number they entered. Output that value. Then, output a sentence that tells which sum is the largest.

For example:

Program Outputs Please enter a positive integer.
User Inputs 14
Program Outputs The sum of all even integers between 1 and 14 is 56.
The sum of all  odd integers between 1 and 14 is 49.
The sum of even numbers is greater.

Example 2:

Program Outputs Please enter a positive integer.
User Inputs 0
Program Outputs 0 is not positive.
Please enter a positive integer.
User Inputs -4
Program Outputs -4 is not positive.
Please enter a positive integer.
User Inputs 31
Program Outputs The sum of all even integers between 1 and 31 is 240.
The sum of all  odd integers between 1 and 31 is 256.
The of odd numbers is greater.

Your program will make use of loops and if statements. Remeber to document your program! Be reminded that this programming assignment is to be your own work. You may use your textbook and class notes, and your Peer Instructor for guidance.

The program must be in a file named program1.java.  Put the program on neelix in your folder.

Please compile and run your program immediately before submitting it.  Never make a change to the code file(s) and turn it in without compiling and running it first.  It is very easy to make a last minute mistake that introduces syntax errors, so checking before submitting can save you an unnecessary grade of 0.