JVAVBigInteger类的使用
2016-03-26 12:07
330 查看
这里列举一下JAVABigInteger类中的加减乘除以及取模的使用,如果用到其他函数,可以查询JAVA函数库:
import java.math.*; import java.text.DecimalFormat; import java.util.Scanner; public class bignum { public static void main(String args[]){ BigInteger a,b; String s; char op; Scanner cin=new Scanner(System.in); while(cin.hasNext()){ a=cin.nextBigInteger(); s=cin.next(); op=s.charAt(0); if(op == '+'){ b=cin.nextBigInteger(); System.out.println(a.add(b)); }else if(op=='-'){ b=cin.nextBigInteger(); System.out.println(a.subtract(b)); }else if(op=='*'){ b=cin.nextBigInteger(); System.out.println(a.multiply(b)); }/*else if(op=='/'){ b=cin.nextBigInteger(); System.out.println(a.divide(b)); }*/else if(op=='%'){ b=cin.nextBigInteger(); System.out.println(a.mod(b)); }else{ BigDecimal a1,b1,eps; String s1,s2,temp; s1=a.toString(); a1=new BigDecimal(s1); b=cin.nextBigInteger(); s2=b.toString(); b1=new BigDecimal(s2); int c=cin.nextInt(); eps=a1.divide(b1,c,4); if(c!=0){ temp="0."; for(int i=0;i<c;i++) temp+="0"; DecimalFormat gd=new DecimalFormat(temp); System.out.println(gd.format(eps)); } else System.out.println(eps); } } } }
相关文章推荐
- VB中数字的交换
- vbox修改虚拟磁盘大小
- VB感受
- VB编程
- 15电气郄慧敏vb作业1在VB中制作计时器
- 15电气郄慧敏vb作业2在VB中制作计时器2
- VB中输出0点几的时候不显示小数点前面的零
- PPT VBA每页的标题进行音标及翻译展示在shapes(2)中
- 把excel中的内容搬迁到PPT中的VBA编程
- VBO、VAO、glVertexPointer()、glVertexAttribPointer()
- vb1
- VB-排序题
- vb作业
- VB15个数字作业
- VB作业
- VB6.0中,日期、时间控件不允许为空时,采用文本框与日期、时间控件相互替换赋值(解决方案)
- VB作业
- VB作业
- vb 学习
- vb 学习