• <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

            基礎(chǔ)知識學(xué)習(xí)
            隨筆 - 4, 文章 - 0, 評論 - 0, 引用 - 0
            數(shù)據(jù)加載中……

            java 分數(shù)類

            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

            久久天天躁狠狠躁夜夜av浪潮 | 午夜不卡888久久| 亚洲欧美精品伊人久久| 久久久久久A亚洲欧洲AV冫| 波多野结衣AV无码久久一区| 久久久久高潮毛片免费全部播放| 精品久久久久久国产牛牛app| 亚洲精品无码久久久久sm| 国产日韩久久免费影院| 蜜臀av性久久久久蜜臀aⅴ| 久久精品人妻一区二区三区| .精品久久久麻豆国产精品| 免费精品国产日韩热久久| 99久久精品国产综合一区| 中文精品久久久久人妻不卡| 人妻无码久久精品| 久久精品人妻一区二区三区| 精品精品国产自在久久高清 | 午夜人妻久久久久久久久| 久久综合九色欧美综合狠狠 | 成人综合伊人五月婷久久| 久久天天婷婷五月俺也去| 久久国产综合精品五月天| 久久伊人精品青青草原高清| 久久精品中文闷骚内射| 久久久www免费人成精品| 久久婷婷色综合一区二区| 欧美伊人久久大香线蕉综合69| 精品久久久久久无码人妻蜜桃| 久久精品国产91久久综合麻豆自制 | 国产亚洲欧美成人久久片 | 久久99精品久久久久久9蜜桃| 久久久久亚洲AV成人片 | 久久国产精品成人免费| 国产亚洲精品自在久久| 无码伊人66久久大杳蕉网站谷歌| 国产精品久久久久蜜芽| 亚洲色大成网站WWW久久九九| 精品熟女少妇AV免费久久| 亚洲国产精品无码久久SM| 久久99精品久久久久久久久久|