Java+大数+高精度

View Code
 1 import java.util.*;

 2 import java.math.*;

 3 import java.text.*;

 4 import java.io.* ;

 5 

 6 public class testjava{

 7     public static void main( String args[] ){

 8         Scanner cin = new Scanner(new BufferedInputStream(System.in)); 

 9         BigInteger a,b;

10         while( cin.hasNext() ){

11             BigInteger t1,t2,t3,t4,t5;

12             a = cin.nextBigInteger();

13             b = cin.nextBigInteger();

14             t1 = a.add( b );

15             t2 = a.subtract( b );

16             t3 = a.multiply( b );

17             t4 = a.divide( b );

18             t5 = a.mod( b );

19             System.out.println( ""+t1 );

20             System.out.println( t2 );

21             System.out.println( t3 );

22             System.out.println( t4 );

23             System.out.println( t5 );

24             //加减乘除+余数

25             int s1;

26             double s2;

27             s1 = t1.intValue();

28             s2 = t2.doubleValue();

29             System.out.println( s1 );

30             System.out.println( s2 );

31             //int,double转化位大数

32             BigDecimal d1;

33             BigDecimal d2 = new BigDecimal("3.141596");

34             System.out.println( d2 );

35             d2 = d2.setScale( 2,BigDecimal.ROUND_HALF_EVEN);

36             //小数位控制

37             System.out.println( d2 );

38             d1 = new BigDecimal( t1 );

39             System.out.println( d1 );//构造方法

40             //大整数转化为Decimal

41             

42             

43             int array_int[] = new int[10];

44             BigInteger array_Big[] = new BigInteger[10];

45             //数组的声明

46             array_Big[9]=BigInteger.valueOf(9);//大整数赋值

47             System.out.println( array_Big[9] );

48             

49         }

50     }

51 }

 

你可能感兴趣的:(java)