• <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ǔ)知識學習
            隨筆 - 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 閱讀(633) 評論(0)  編輯 收藏 引用 所屬分類: Algorithm

            亚洲精品乱码久久久久久自慰| 久久精品夜色噜噜亚洲A∨| 久久久久久噜噜精品免费直播 | 久久久久国产精品麻豆AR影院 | 亚洲中文久久精品无码| 欧美精品久久久久久久自慰| 久久这里只有精品首页| 久久婷婷五月综合成人D啪| 久久强奷乱码老熟女网站| 国内精品伊人久久久久AV影院| 91久久精品国产91性色也| 久久久久婷婷| 狠狠干狠狠久久| 狠狠色丁香久久婷婷综合蜜芽五月| jizzjizz国产精品久久| 久久精品二区| 四虎国产精品免费久久5151| 成人久久免费网站| 久久久无码精品亚洲日韩软件| 久久久无码精品亚洲日韩蜜臀浪潮| 久久青青草原精品国产不卡| 国产精品美女久久久久| 国产成人精品综合久久久久| 精品久久久久久久久久中文字幕 | 久久久久亚洲精品无码蜜桃 | 波多野结衣久久| 久久丝袜精品中文字幕| 国产美女久久久| 久久婷婷五月综合国产尤物app| 久久久久97国产精华液好用吗| 久久国产精品成人影院| 久久精品日日躁夜夜躁欧美| 久久久久久久久久久免费精品| Xx性欧美肥妇精品久久久久久| 97久久香蕉国产线看观看| 色综合久久综合中文综合网| 一本色道久久88—综合亚洲精品| 久久只这里是精品66| 久久久久亚洲精品日久生情| 亚洲欧美一区二区三区久久| 久久无码国产专区精品|