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

            国产精品xxxx国产喷水亚洲国产精品无码久久一区| 国产免费久久精品丫丫| 久久久久久久综合日本| 欧美日韩中文字幕久久久不卡| 亚洲日韩欧美一区久久久久我| 国产亚洲色婷婷久久99精品91| 亚洲精品无码久久毛片 | 久久精品国产99国产精品亚洲| 性高朝久久久久久久久久| 热综合一本伊人久久精品| 中文国产成人精品久久不卡| 四虎国产永久免费久久| 欧美黑人激情性久久| 国产精品久久久久久影院| 久久男人中文字幕资源站| 国内精品伊人久久久久| 热久久国产欧美一区二区精品| 性做久久久久久久| 久久99精品免费一区二区| 国产色综合久久无码有码| 狠狠色丁香婷婷综合久久来来去| 久久婷婷成人综合色综合| 亚洲国产精品成人AV无码久久综合影院| 无码国内精品久久综合88 | 精品水蜜桃久久久久久久| 亚洲精品无码久久千人斩| 久久综合综合久久97色| 午夜天堂av天堂久久久| 欧美亚洲国产精品久久| 欧美精品一区二区久久| 国产精品九九久久免费视频| 2022年国产精品久久久久| 中文字幕乱码久久午夜| 久久无码国产专区精品| 色婷婷久久久SWAG精品| 99久久精品国产一区二区| 久久综合久久伊人| 久久精品无码一区二区app| 国产精品成人精品久久久| 久久国产高清一区二区三区| 国产精品熟女福利久久AV|