• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            Try Again

            基礎知識學習
            隨筆 - 4, 文章 - 0, 評論 - 0, 引用 - 0
            數據加載中……

            java 分數類

            class Fraction
            {
                BigInteger up, down;
                
            public Fraction (Fraction f)
                {
                    
            this.up = f.up;
                    
            this.down = f.down;
                }
                
            public Fraction(String s)
                {
                    
            this.up = new BigInteger(s);
                    
            this.down = new BigInteger("1");
                }
                
            public Fraction(BigInteger a, BigInteger b)
                {
                    
            this.up = a;
                    
            this.down = b;
                }
                
            public BigInteger getUp()
                {
                    
            return this.up;
                }
                
            public BigInteger getDown()
                {
                    
            return this.down;
                }
                
            public Fraction subtract(Fraction f)
                {
                    BigInteger save1 
            = this.up.multiply (f.down);
                    BigInteger save2 
            = f.up.multiply(this.down);
                    Fraction tmp 
            = new Fraction(save1.subtract (save2), f.down .multiply ( this.down));
                    
            return simplex(tmp);
                }
                
            public Fraction add(Fraction f)
                {
                    Fraction tmp 
            = new Fraction ("0");
                    tmp 
            = tmp.subtract(f);
                    Fraction ans 
            = new Fraction (this.subtract(tmp));
                    
            return ans;
                }
                
            public Fraction multiply(Fraction f)
                {
                    Fraction tmp;
                    tmp 
            = new Fraction(this.up.multiply (f.up), this.down.multiply (f.down));
                    
            if (tmp.down.compareTo(new BigInteger("0")) == -1)
                    {
                        tmp.down 
            = tmp.down.multiply (new BigInteger("-1"));
                        tmp.up 
            = tmp.up.multiply (new BigInteger("-1"));
                    }
                    
            return simplex(tmp);
                }
                
            public Fraction divide(Fraction f)
                {
                    Fraction tmp 
            = null;
                    tmp 
            = new Fraction(this.up.multiply (f.down), this.down.multiply (f.up));
                    
            if (tmp.down.compareTo(new BigInteger("0")) == -1)
                    {
                        tmp.down 
            = tmp.down.multiply (new BigInteger("-1"));
                        tmp.up 
            = tmp.up.multiply (new BigInteger("-1"));
                    }
                    
            return simplex(tmp);
                }
                BigInteger gcd(BigInteger a, BigInteger b)
                {
                    
            if (b.compareTo(new BigInteger("0")) == 0)
                        
            return a;
                    
            return gcd(b, a.remainder (b));
                }
                Fraction simplex(Fraction f)
                {
                    BigInteger tmp 
            = gcd(f.up.abs(), f.down.abs ());
                    f.up 
            = f.up.divide (tmp);
                    f.down 
            = f.down.divide (tmp);
                    
            return f;
                }
                
            void print()
                {
                    BigInteger a, b, c;
                    a 
            = this.getUp ();
                    b 
            = this.getDown();
                    c 
            = gcd(a.abs(), b.abs());
                    a 
            = a.divide (c);
                    b 
            = b.divide (c);
                    
            if (b.compareTo (new BigInteger("1")) == 0)
                        System.out.println(a);
                    
            else
                        System.out.println (a 
            + "/" + b);
                }
            }

            posted on 2009-03-08 21:02 NicYun 閱讀(634) 評論(0)  編輯 收藏 引用 所屬分類: Algorithm

            欧美粉嫩小泬久久久久久久| 久久影视综合亚洲| 97精品依人久久久大香线蕉97| 精品久久久久久久久久中文字幕| 久久久久久免费一区二区三区| 国产精品久久久久久| 国产产无码乱码精品久久鸭| 久久久青草青青亚洲国产免观| 色噜噜狠狠先锋影音久久| 久久国产午夜精品一区二区三区| 人妻精品久久久久中文字幕| 久久经典免费视频| 久久精品中文字幕无码绿巨人| 亚洲欧美成人综合久久久| 久久99精品综合国产首页| 久久精品国产亚洲5555| 久久精品aⅴ无码中文字字幕不卡| 亚洲精品tv久久久久久久久| 久久九九亚洲精品| 色狠狠久久综合网| 国产亚州精品女人久久久久久 | 久久久精品久久久久久| 久久强奷乱码老熟女网站| 国产综合久久久久| 亚洲精品tv久久久久| 国产美女久久精品香蕉69| 久久精品国产72国产精福利| 亚洲第一极品精品无码久久| 精品久久人人爽天天玩人人妻 | 99热精品久久只有精品| 久久久久久久精品成人热色戒| 999久久久免费国产精品播放| 欧美亚洲国产精品久久| 久久精品国产亚洲精品| 久久精品国产99国产精品澳门| 18岁日韩内射颜射午夜久久成人| www亚洲欲色成人久久精品| 人妻精品久久无码专区精东影业| 亚洲Av无码国产情品久久| 久久av免费天堂小草播放| 精品综合久久久久久97超人|