开发者

how can I use biginteger in java

开发者 https://www.devze.com 2023-01-29 00:24 出处:网络
i have this code and i want to change it to BigInteger import java.util.*; public class Euclid { long TIME;

i have this code and i want to change it to BigInteger

import java.util.*;
public class Euclid {
    long TIME;
    long start = System.currentTimeMillis();
    private static final String EXCEPTION_MSG = 
        开发者_如何学运维"Invalid value (%d); only positive integers are allowed. ";

    public static int getGcd( int a, int b)

    {//long start = System.currentTimeMillis();
        if (a < 0)
        {
            throw new IllegalArgumentException(String.format(EXCEPTION_MSG, a));
        }
        else 
            if (b < 0) 
            { 
                throw new IllegalArgumentException(String.format(EXCEPTION_MSG, b));
            }

        while (b != 0)
        {               
            if (a > b) 
            {
                a = a - b;
            }      
            else 
            {
                b = b - a;
            }    
        }
        return a;
        //long timeTaken = System.currentTimeMillis() - start;
    }
}


Here's a example: http://www.roseindia.net/java/java-biginteger/java-biginteger.shtml

0

精彩评论

暂无评论...
验证码 换一张
取 消