华南俳烁实业有限公司

java

當前位置:中華考試網(wǎng) >> java >> java面試題 >> 文章內(nèi)容

java認證考試編程題(8)

來源:中華考試網(wǎng)  [2016年10月4日]  【

給出大整數(shù)加減法的實現(xiàn)思路,例如,199999999999999998+333333333333333333333,或者123444444444447654-999999999999988877。

 

代碼實現(xiàn)如下:

import java.math.*;

public class BigIntegerTest

{

public static void main(String[] args)

{

BigInteger result;

BigInteger BI1 = new BigInteger("199999999999999998"); //把一個字符串翻譯為一個 BigInteger ,該字符串包含可選的負號,后面跟著一個或多個十進制數(shù)字序列。

  result = BI1.add(new BigInteger("333333333333333333333")); //返回一個 BigInteger ,其值是 (this + val) 。

System.out.println(result);

BigInteger BI2 = new BigInteger("123444444444447654"); //把一個字符串翻譯為一個 BigInteger ,該字符串包含可選的負號,后面跟著一個或多個十進制數(shù)字序列。

   result = BI2.subtract(new BigInteger("999999999999988877")); //返回一個 BigInteger ,其值是 (this - val)。

System.out.println(result);

}

}

責編:sunny
  • 會計考試
  • 建筑工程
  • 職業(yè)資格
  • 醫(yī)藥考試
  • 外語考試
  • 學歷考試
福海县| 芦溪县| 海南省| 伊吾县| 武强县| 新宾| 榕江县| 巧家县| 大余县| 灯塔市| 九龙坡区| 宁明县| 枣强县| 洛阳市| 阳原县| 桂阳县| 安康市| 蓬莱市| 什邡市| 福贡县| 乌苏市| 文水县| 桦甸市| 雅安市| 高邑县| 同德县| 泸水县| 陆川县| 庆安县| 广宗县| 理塘县| 马鞍山市| 襄垣县| 盐亭县| 北辰区| 卢氏县| 汽车| 寻乌县| 马山县| 崇州市| 台北县|