Jump to content

problem with classe fraction

- - - - -

  • Please log in to reply
1 reply to this topic

#1
carlitos2012

carlitos2012

    Newbie

  • Members
  • Pip
  • 4 posts
I am having troubles with my programming I'm new on this java program and need to do this.
The goal of this programming assignment is to find the sum of
1/1 + 1/2 + 1/3 + ... + 1/1000 in terms of a fraction, not as decimal
number. I can use Provide methods display(),
isWhole(), returnNumerator(), returnDenominator(), returnDecimal().

thanks for help....

#2
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Java
Do you HAVE TO use/code these methods?
display(), isWhole(), returnNumerator(), returnDenominator(), returnDecimal().

I mean, if you rewrite 1/1 + 1/2 + 1/3 + ... you can get this:
(1000/1)/1000 + (1000/2)/1000 + (1000/3)/1000 ...

To display it as fraction you just drop all the /1000
double result = (1000/1)+ (1000/2)/+ (1000/3) +...
and then display as fraction:
System.out.println(result +"/1000");

You just need to calculate the result with use of a loop and you're done.. no idea why you would need so many methods.. i'd have like ..2 methods :D calculate(), and display()




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users