tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 
 Tools and Libs > Uncommons Maths > Rational Numbers

Rational Numbers 

Uncommons Maths is a java library with nice math utilities and random number generators. This requires the library uncommons-maths-1.2.2.jar to be in classpath. The following example shows using Rational class.

File Name  :  
com/bethecoder/tutorials/uncommons/RationalNumberTest.java 
Author  :  Sudhakar KV
Email  :  kvenkatasudhakar@gmail.com
   
package com.bethecoder.tutorials.uncommons;

import org.uncommons.maths.number.Rational;

public class RationalNumberTest {

  /**
   @param args
   */
  public static void main(String[] args) {
    
    Rational a = Rational.QUARTER;
    Rational b = Rational.HALF;
    Rational c = a.add(b);
    
    System.out.println(a + "+" + b + " = " + c);
    
    
    a = new Rational(18);
    b = new Rational(38);
    c = a.add(b);
    
    System.out.println(a + "+" + b + " = " + c);
    
    a = new Rational(417);
    b = new Rational(813);
    c = a.add(b);
    
    System.out.println(a + "+" + b + " = " + c);
  }

}
   

It gives the following output,
1/4+1/2 = 3/4
1/8+3/8 = 1/2
4/17+8/13 = 188/221


                    Print

   



Books Recommendation

 
 
bl  br