Enjoy an ad free experience by logging in. Not a member yet? Register.

Results 1 to 7 of 7
Thread: java, cant figure this out

02232006, 07:11 AM #1
 Join Date
 Feb 2006
 Posts
 11
 Thanks
 0
 Thanked 0 Times in 0 Posts
java, cant figure this out
i have the deitel 6th edition how to program java book.
On page 227 example 5.12 it says:
"Write an application that calculates the prduct of the odd integers from 1 to 15."
That is all it says...does it mean multiply all the odd numbers from 1 to 15? If so how do i do this....im not sure how to point out negative numbers.

02232006, 02:26 PM #2
 Join Date
 May 2002
 Location
 Marion, IA USA
 Posts
 6,298
 Thanks
 4
 Thanked 84 Times in 83 Posts
I'd probably get clarification from your teacher on that one. It can be interpreted a few different ways.
My interpretation would be that you need to come up with an algorithm to compute the product for every combination of odd integers from 1  15. Obviously you wouldn't manually write out every combination so that means you need one or more loops and some code to determine if the two integers are odd and then multiply them together and do so for every combination of odd integers. So for example you want to:
1x1 = 1
1x3 = 3
1x5 = 5
1x7 = 7
1x9 = 9
1x11 = 11
1x13 = 13
1x15 = 15
3x1 = 3
3x3 = 9
3x5 = 15
.
.
.
until you get to
15x15 = 225
Another question would be if it wants you to exclude duplicate calculations. Obviously you would have already done 1x3 so do you need to also include 3x1.Spookster
CodingForums Supreme Overlord
All Hail Spookster

02232006, 02:56 PM #3
 Join Date
 Feb 2005
 Location
 Bradford, UK
 Posts
 3,192
 Thanks
 19
 Thanked 66 Times in 65 Posts
I would guess it means 1x3x5x7x9x11x13x15. Technically thats what its asking, if it wanted spooksters example it should have said 'products' as you end up with multiple answers.
Ofcourse what a question asks for and what it wants are not always the same thing
I'm assuming the book has answers in it too? If so, ask a friend to look up the answer.

02232006, 03:27 PM #4
 Join Date
 Feb 2006
 Location
 US
 Posts
 33
 Thanks
 0
 Thanked 0 Times in 0 Posts
Code:int product = 1; for (int i = 1; i <= 15, i+=2) product *= i;
Code:public int oddFactorial(int i) { if (i == 1) return 1; return i * oddFactorial(i2); }

02232006, 05:13 PM #5
 Join Date
 Feb 2006
 Posts
 11
 Thanks
 0
 Thanked 0 Times in 0 Posts
i tried both of those ways and cant seem to get either to work.

02232006, 06:03 PM #6
 Join Date
 May 2002
 Location
 Marion, IA USA
 Posts
 6,298
 Thanks
 4
 Thanked 84 Times in 83 Posts
Originally Posted by EnderSpookster
CodingForums Supreme Overlord
All Hail Spookster

02242006, 12:07 AM #7
 Join Date
 Feb 2006
 Location
 US
 Posts
 33
 Thanks
 0
 Thanked 0 Times in 0 Posts
Originally Posted by Uber Fr0g
Originally Posted by spookster