/* (程序頭部註釋開始)
* 程序的版權和版本聲明部分
* Copyright (c) 2011, 煙臺大學計算機學院學生
* All rights reserved.
* 文件名稱:判斷兩個日期的大小關係
* 作 者: 雷恆鑫
* 完成日期: 2012 年 10 月 31 日
* 版 本 號: V1.0
* 對任務及求解方法的描述部分
* 輸入描述:
* 問題描述:
* 程序輸出:
* 程序頭部的註釋結束
*/
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
BigInt big = new BigInt("123456", "9876543219");
big.add();
big.cut();
big.multiply();
big.divide();
big.factorCount();
//new MyJFrame();
}
}
BigIntegerBigInteger類
import java.math.BigInteger;
import java.math.*;
public class BigInt {
BigInteger m1;
BigInteger m2;
BigInteger m3;
BigInt(String s1, String s2) {
m1 = new BigInteger(s1);
m2 = new BigInteger(s2);
}
public void add() {
m3 = m1.add(m2);
System.out.println("兩個數的和爲:" + m3);
}
public void cut() {
m3 = m1.subtract(m2);
System.out.println("兩個數的差爲:" + m3);
}
public void multiply() {
m3 = m1.multiply(m2);
System.out.println("兩個數的積爲:" + m3);
}
public void divide() {
m3 = m1.divide(m2);
System.out.println("兩個數的商爲:" + m3);
}
public void factorCount() {
int count = 0;
for (BigInteger i = BigInteger.valueOf(2); i.compareTo(m1) < 0; i = i
.add(BigInteger.ONE)) {
if (m1.remainder(i).equals(BigInteger.ZERO)) {
++count;
}
}
System.out.println(m1 + "的因子個數爲:" + count);
}
}
運行結果: