Need Help!!
Posted: 21 April 2005 03:07 PM     [ Ignore ]  
You > Me
Total Posts:  79
Joined  2005-01-15

Thanks, that helped a lot smile

Profile
 
Posted: 21 April 2005 03:07 PM   [ # 1 ]     [ Ignore ]   [ # 1 ]  
You > Me
Total Posts:  79
Joined  2005-01-15

I need help on writing a java program for my intro CS class.

here is the program i need to write:

Given a list of 10 positive intiger values, write a java program to calculate and print sum of all even and sum of all odd values in the list. Test our list with the following set values:

45
66
22
25
12
14
5
9
15
16

I need to use for loops for this program.

Any help will be great and Thanks in advance.

Profile
 
Posted: 21 April 2005 03:22 PM   [ # 2 ]     [ Ignore ]   [ # 2 ]  
Board Mentor
Total Posts:  2742
Joined  2004-09-29

Are you going to input them or are they embedded in the source code?

Profile
 
Posted: 21 April 2005 03:28 PM   [ # 3 ]     [ Ignore ]   [ # 3 ]  
You > Me
Total Posts:  79
Joined  2005-01-15

I am going to input them

Profile
 
Posted: 21 April 2005 05:16 PM   [ # 4 ]     [ Ignore ]   [ # 4 ]  
Board Mentor
Total Posts:  2742
Joined  2004-09-29

Ok .

have three variable you will be updating: counter, oddTotal and evenTotal
Set them all @ zero.

first ask the user how many inputs .... that will be your counter for the loop.

then you get the first input, this will be taken in as a String so remember to convert to an Integer

Once you convert you check if it is odd or even by dividing by two and checking if it is zero

if (input/2 ==0)

if it is odd then
oddTotal = oddTotal + input;

if it is even then
evenTotal = evenTotal + input;

After that you just output the results smile

Hope that helps!  smile

Profile
 
 
 
 
‹‹ Can I do this.      First Thread Alive ››