Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Reducing fractions problem  RSS feed

 
David Powers
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am writing a program that needs to reduce fractions. I am having trouble working out the process of it (the loop type and the code inside the loop).

Can anyone assist me? Thank you.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

This particular forum is for discussing this site. We've got plenty of other forums, including a Beginner's Java Forum where this question would be more appropriate. I'm going to move it there for you.
 
Julian Kennedy
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi David,

Can you post the code that you have so far (using the UBB [code] and [/code] tags to preserve the layout). That way people can guide you along the process to help you learn, rather than writing the code for you.

Have you looked up an algorithm for reducing fractions? Obviously some algorithms will be more efficient than others. Is that a factor?

Jules
 
David Powers
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's what I've written so far. It only works for some fractions. I'm looking for the greatest common factor, starting from the numerator and checking each number until it finds it or gets to zero.

 
David Powers
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Julian Kennedy:
Hi David,

Can you post the code that you have so far (using the UBB [code] and [/code] tags to preserve the layout). That way people can guide you along the process to help you learn, rather than writing the code for you.

Have you looked up an algorithm for reducing fractions? Obviously some algorithms will be more efficient than others. Is that a factor?

Jules

OK, I figured it out. I used a for loop and a break statement. Thanks for your help!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!