Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-23-2006, 06:11 AM   PM User | #1
Uber Fr0g
New Coder

 
Join Date: Feb 2006
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Uber Fr0g is an unknown quantity at this point
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.
Uber Fr0g is offline   Reply With Quote
Old 02-23-2006, 01:26 PM   PM User | #2
Spookster
Supreme Overlord


 
Spookster's Avatar
 
Join Date: May 2002
Location: Marion, IA USA
Posts: 6,220
Thanks: 4
Thanked 80 Times in 79 Posts
Spookster will become famous soon enough
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
Who gave you that Ugging infraction? Yeah that's right it was me!
Spookster is offline   Reply With Quote
Old 02-23-2006, 01:56 PM   PM User | #3
NancyJ
Senior Coder

 
NancyJ's Avatar
 
Join Date: Feb 2005
Location: Bradford, UK
Posts: 3,162
Thanks: 19
Thanked 65 Times in 64 Posts
NancyJ will become famous soon enough
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.
__________________
http://www.hazelryan.co.uk
NancyJ is offline   Reply With Quote
Old 02-23-2006, 02:27 PM   PM User | #4
Ender
New Coder

 
Join Date: Feb 2006
Location: US
Posts: 33
Thanks: 0
Thanked 0 Times in 0 Posts
Ender is an unknown quantity at this point
Code:
int product = 1;
for (int i = 1; i <= 15, i+=2)
         product *= i;
or you can do it recursively.
Code:
public int oddFactorial(int i)
{
      if (i == 1)
         return 1;     
      return i * oddFactorial(i-2);
}
Ender is offline   Reply With Quote
Old 02-23-2006, 04:13 PM   PM User | #5
Uber Fr0g
New Coder

 
Join Date: Feb 2006
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Uber Fr0g is an unknown quantity at this point
i tried both of those ways and cant seem to get either to work.
Uber Fr0g is offline   Reply With Quote
Old 02-23-2006, 05:03 PM   PM User | #6
Spookster
Supreme Overlord


 
Spookster's Avatar
 
Join Date: May 2002
Location: Marion, IA USA
Posts: 6,220
Thanks: 4
Thanked 80 Times in 79 Posts
Spookster will become famous soon enough
Quote:
Originally Posted by Ender
Code:
int product = 1;
for (int i = 1; i <= 15, i+=2)
         product *= i;
or you can do it recursively.
Code:
public int oddFactorial(int i)
{
      if (i == 1)
         return 1;     
      return i * oddFactorial(i-2);
}
Why would you just provide a solution to what likely is a homework assignment? They didn't ask for a solution. They asked for an explanation of what the book was asking. The book he/she is using is used in the classroom for programming courses and those questions are normally assigned for homework.
__________________
Spookster
CodingForums Supreme Overlord
All Hail Spookster
Who gave you that Ugging infraction? Yeah that's right it was me!
Spookster is offline   Reply With Quote
Old 02-23-2006, 11:07 PM   PM User | #7
Ender
New Coder

 
Join Date: Feb 2006
Location: US
Posts: 33
Thanks: 0
Thanked 0 Times in 0 Posts
Ender is an unknown quantity at this point
Quote:
Originally Posted by Uber Fr0g
i tried both of those ways and cant seem to get either to work.
They do work. Can you not debug a comma? Learn to program.

Quote:
Originally Posted by spookster
Why would you just provide a solution to what likely is a homework assignment? They didn't ask for a solution. They asked for an explanation of what the book was asking. The book he/she is using is used in the classroom for programming courses and those questions are normally assigned for homework.
I'm sorry, I know I shouldn't have given solutions, as he obviously posted his homework. I don't know why I answered like that... partly because it was early in the morning and I had not gotten a lot of sleep, and partly because of strange, subconscious, contemptuous reasons.
Ender is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:50 PM.


Advertisement
Log in to turn off these ads.