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

            99久久精品无码一区二区毛片 | 国内精品久久九九国产精品| 亚洲av成人无码久久精品| 日韩精品久久久久久免费| 99久久这里只有精品| 欧美国产精品久久高清| 精品伊人久久久| 国产欧美一区二区久久| 亚洲欧洲中文日韩久久AV乱码| 97精品依人久久久大香线蕉97 | 久久久精品人妻一区二区三区四 | 久久精品这里热有精品| 亚洲国产精品成人AV无码久久综合影院| 久久99久国产麻精品66| 办公室久久精品| 日本欧美久久久久免费播放网| 久久国产成人精品国产成人亚洲| 亚洲色欲久久久综合网| 婷婷久久综合九色综合九七| 国产精品久久久天天影视| 亚洲日本久久久午夜精品| 久久精品国产第一区二区| 国产精品99久久99久久久| 久久精品国产亚洲αv忘忧草| 国产成人无码精品久久久久免费| 久久精品a亚洲国产v高清不卡| 久久这里都是精品| 久久久久久久亚洲精品| 国产高清美女一级a毛片久久w | 久久91精品国产91| 色综合久久88色综合天天 | 久久精品三级视频| 国内精品久久久久久久涩爱| 99久久精品无码一区二区毛片| 日本精品久久久久中文字幕8| 2021久久精品国产99国产精品| 久久久久高潮毛片免费全部播放 | 国产成人精品综合久久久| 国产精品久久久久久久人人看 | 日本福利片国产午夜久久| 久久国产精品-国产精品|