Results 1 to 2 of 2
  1. #1
    lenny is offline Member
    Join Date
    Jul 2007
    Posts
    40
    Rep Power
    0

    Default Finding GCF in java

    Hi, I'm doing a project with Java, and I need to find the GCF of a fraction. I really don't know how to do this, and would like a code to basically reduce the fraction. Like 12 over 6. The GCF is 6, and the fraction is reduced to 2 over 1.

    I am using J builder, not sure if it would make a difference
    Thanks.

  2. #2
    brianhks is offline Senior Member
    Join Date
    Jul 2007
    Posts
    135
    Rep Power
    0

    Default

    Start with the number that is the smallest (numerator or denominator) and then count down trying each one to see if they can divide evenly into both. The way to tell is to use the mod operator '%' and see if the answer is zero.

Similar Threads

  1. Finding Median of X Integers
    By Hasan in forum New To Java
    Replies: 3
    Last Post: 08-12-2008, 02:06 PM
  2. Finding elements in a vector
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-14-2008, 08:37 PM
  3. Finding arguments of Servlet
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-25-2008, 07:04 PM
  4. Finding the character set of a FILE
    By javaplus in forum Advanced Java
    Replies: 1
    Last Post: 01-22-2008, 06:36 AM
  5. Finding largest no
    By bugger in forum New To Java
    Replies: 11
    Last Post: 11-29-2007, 12:49 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •