File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Help with Rationals Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Help with Rationals" Watch "Help with Rationals" New topic

Help with Rationals

Stacey Johnson
Ranch Hand

Joined: Jan 11, 2004
Posts: 55
Hi All,
I'm working on an assignment that wants me to write a program that will compute the following summation series using rational class:
1/1 + 1/2 + 1/3 + ...+ 1/n
1/1 + 1/2 + 1/2e2 +...+ 1/2en
Now I'm working on the first part and I think I've got that kinda figured out, but now I need help on the second part. I've never worked with exponents before so I'm not too sure where to go from here.
My code is as follows:

Thanks in advance for the help
Tim West
Ranch Hand

Joined: Mar 15, 2004
Posts: 539
Well, 2e2 is 2 * (10 ^ 2). So the second series you gave looks to me like this:
1/1 + 1/2 + 1/200 + 1/2000 + 1/20000 + ...
Is that your intention? The first two terms don't fit with the remainder (1/2 and 1/20 would fit better with the rest of the series). The first two terms make me think you're going to go
1/2 + 1/2 + 1/4 + 1/8 + 1/16 + ...
Either way, with the rational class you've got, it's just a case of working out what series of fractions you want, and adding them as you did in the code you posted. Post back and people will help you with this if you need it.

[ April 15, 2004: Message edited by: Tim West ]
Stacey Johnson
Ranch Hand

Joined: Jan 11, 2004
Posts: 55
In response to Tim's post, my intention for the second part is to go
1/1 + 1/2 + 1/2e2 + 1/2e3 + 1/2e4 +...+1/2en
"n" being my choice of what I want to stop it at.
What is throwing me off is that I start with 1/1 + 1/2 and then I go into the exponents of 1/2e2 etc.. This is where I don't know how to go about it.
So if anyone can help, I would appreciate it.
Thanks in advance
Tom Blough
Ranch Hand

Joined: Jul 31, 2003
Posts: 263
1/1 is the same as 1/2e0 and 1/2 is the same as 1/2e1, so you can treat them all as exponentiated numbers.
Are you sure that it is 2en (i.e. 2*10^n), and not 2 raised to the power of n (i.e. 2^n)? The former is a strange series, the later is the geometric series where the sum approaches 1 as n approaces infinity.
[ April 16, 2004: Message edited by: Tom Blough ]

Tom Blough<br /> <blockquote><font size="1" face="Verdana, Arial">quote:</font><hr>Cum catapultae proscriptae erunt tum soli proscripti catapultas habebunt.<hr></blockquote>
Stacey Johnson
Ranch Hand

Joined: Jan 11, 2004
Posts: 55
I'm confused with the exponent and raised to the power questions. I don't get the difference. I see the difference but I don't understand it. What am I missing? I think it would be to the raised power but I don't know. My first message is exactly what the excersise told me to do. So I'm not too sure which way to interpret it.
I agree. Here's the link:
subject: Help with Rationals
It's not a secret anymore!