+ Reply to Thread
Results 1 to 8 of 8

Thread: Simplifying Fractions on Java

  1. #1

    Default Simplifying Fractions on Java

    I'm making a Fraction calculator and i've gotten to the point where i can solve it to it's final answer, the only problem i'm stumped on is how to simplify the final answer. plz help

  2. #2
    yep Gray Spaceman Gray Spaceman Gray's Avatar
    Join Date
    Feb 2009
    Location
    seattle. wa
    Posts
    1,296
    Blog Entries
    1

    Default

    lookup how modulo works, you'll need to find remainders here.

  3. #3
    nox Spaceman nox Spaceman nox's Avatar
    Join Date
    Jan 2008
    Location
    no love for bitches
    Posts
    4,534

    Default

    divide the fraction each number of the fraction by the denominator.. if the denominator yields a non integer # then its no good
    Last edited by nox; 11-03-2009 at 07:34 PM.

  4. #4

    Default

    find the least common factors of the denominator and numerator and just cancel like terms... unless i'm missing the point do you have like Integer1/Integer2 ?

  5. #5

    Default

    uhmm
    create a new class
    and you're gonna have to do it contructor style like how ure last thread was...

    and try this
    Code:
    private void Reduce(){
        	int a = numerator;
        	int b = denominator;
        	int c = 0;
    
        	while( b!= 0 )
        	{
        		c = a % b;
        		a = b;
        		b = c;
        	}
        	denominator/=a;
        	numerator/=a;
        }

    i did this last week in my comp sci class.
    We Gettin' -بجدية Money!

  6. #6
    street magician david blaine Spaceman david blaine Spaceman david blaine's Avatar
    Join Date
    May 2005
    Posts
    5,755

    Default

    Quote Originally Posted by pimpleon View Post
    uhmm
    create a new class
    and you're gonna have to do it contructor style like how ure last thread was...

    and try this
    Code:
    private void Reduce(){
        	int a = numerator;
        	int b = denominator;
        	int c = 0;
    
        	while( b!= 0 )
        	{
        		c = a % b;
        		a = b;
        		b = c;
        	}
        	denominator/=a;
        	numerator/=a;
        }

    i did this last week in my comp sci class.
    wtf is this shit

    Code:
    package reduce;
    
    public class Reduce
    {
           private int numerator;
           private int denominator;
    
            public static void main (String[] args)
            { 
                Reduce(2, 4); // example call
            }
    
            public void Reduce(int numerator, int denominator)
            {
            	int numerator = this.numerator;
            	int denominator = this.denominator;
            	int c = 0;
    
            	while( b != 0 )
            	{
        	        	c = numerator % denominator;
        	        	numerator = denominator;
        		        denominator = c;
        	         }
    
        	denominator/=a;
        	numerator/=a;
    
            System.out.print(numerator + "\n" + denominator);
        }
    }

  7. #7

    Default

    lol mx. basically the same thing broe...

    i had it so he'd have to create another class cause in hte OP he said he got everything down but the reducing...
    so when it was done evaluating what ever code he did have he'd just have to put
    Reduce(numerator,denominator);
    in his main class, without him havin to change up or move his code around
    We Gettin' -بجدية Money!

  8. #8

+ Reply to Thread

Bookmarks

Posting Permissions

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