大数

1、java:

 1 import java.util.*;
 2 import java.math.*;
 3 public class Main {
 4     public static void main(String args[]){
 5         Scanner cin = new Scanner(System.in);
 6         BigInteger a,b;
 7         
 8         while(cin.hasNext()){
 9             a=cin.nextBigInteger();
10             b=cin.nextBigInteger();
11             //四则运算
12             System.out.println(a.add(b));//
13             System.out.println(a.subtract(b));//
14             System.out.println(a.multiply(b));//
15             System.out.println(a.divide(b));//
16             System.out.println(a.remainder(b));//取模
17             //比较
18             if(a.compareTo(b)==0) System.out.println("a==b");
19             else if(a.compareTo(b)>0) System.out.println("a>b");
20             else if(a.compareTo(b)<0) System.out.println("a<b");
21             //十进制表示
22             System.out.println(a.toString());
23             //返回大整数p进制的制服表示
24             int p=8;
25             System.out.println(a.toString(p));
26         }
27     }
28 }

 

posted @ 2016-04-17 11:22  fenicnn  阅读(259)  评论(0编辑  收藏  举报