Source code for RationalDemo.java

What follows is the highlighted source code with comments. You can also download this file directly: RationalDemo.java.

/*
 * This work by W. Patrick Hooper is free of known copyright restrictions.
 * The work is in the public domain.
 * 
 * Author's website: <a href="http://wphooper.com">http://wphooper.com</a>. 
 */

package number;

/**
 * This program demonstrates the use of the Rational and RationalField classes.
 * @author Pat Hooper
 */
public class RationalDemo {

    
    public static void main(String[] args) {
        RationalField Q=new RationalField();
        Rational a=new Rational(1,2);
        Rational b=new Rational(1,3);
        Rational c=Q.add(a, b);
        System.out.println("a="+a);
        System.out.println("b="+b);
        System.out.println("a+b="+c);        
    }

}
HOOPER >>>>> JAVA TUTORIAL
Last modified on August 17, 2018.
[check html] [check css]