在包 hugeinteger 中創(chuàng)建功能類 HugeInteger,該類用來存放和操作一個(gè)不超過
40 位的大整數(shù)。
(1) 定義一個(gè)構(gòu)造函數(shù),用來對(duì)大整數(shù)進(jìn)行初始化。參數(shù)為一個(gè)字符串。
(2) 定義 input 成員函數(shù),實(shí)現(xiàn)大整數(shù)的重新賦值。參數(shù)為一個(gè)字符串,無返回
值。
(3) 定義 output 成員函數(shù),將大整數(shù)輸出到屏幕上。無參數(shù)無返回值。
(4) 定義 add 成員函數(shù),實(shí)現(xiàn)兩個(gè)大整數(shù)的加法。參數(shù)為一個(gè) HugeInteger 對(duì)
象,無返回值,例如:
HugeInteger A = new HugeInteger("12345");
HugeInteger B = new HugeInteger("1234");
A.add(B);
此時(shí),A 為 13579,B 為 1234。
(5) 定義 sub 成員函數(shù),實(shí)現(xiàn)兩個(gè)大整數(shù)的減法。參數(shù)和返回值同 add 函數(shù)。
(6) 定義若干大整數(shù)關(guān)系運(yùn)算的成員函數(shù),包括 isEqualTo(等于,=)、
isNotEqualTo(不等于,≠)、isGreaterThan(大于,>)、isLessThan(小
于,<)、isGreaterThanOrEqualTo(大于等于,≥)和 isLessThanOrEqualTo
(小于等于,≤)。這些函數(shù)的參數(shù)為一個(gè) HugeInteger 對(duì)象,返回值為一個(gè)
布爾類型,表示關(guān)系運(yùn)算的結(jié)果,例如:
HugeInteger A = new HugeInteger("12345");
HugeInteger B = new HugeInteger("1234");
那么此時(shí) A.isGreaterThan(B)的結(jié)果應(yīng)當(dāng)為 True,表示 12345>1234。
標(biāo)簽:
java
整數(shù)
運(yùn)算
上傳時(shí)間:
2019-06-01
上傳用戶:idealist