// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
public class Fraction {
    private final static double EPS = 0.0000001;
    private int a;
    private int b;
    private Fraction(int a, int b) {
        this.a = a;
        this.b = b;
    }
    public static Fraction calc(double x) {
        int a2 = 1;
        int b2 = 2;
        double x2;
        for(;;) {
           x2 = (double)a2/(double)b2;
           if((Math.abs(x2-x) / x) < EPS) break;
           if(x2>x) {
              b2++;
           } else {
              a2++;
           }
        }
        return new Fraction(a2, b2);
    }
    public String toString() {
        return (a + "/" + b);
    }
}
