Java大数练习

大数阶乘

题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=28

 1 import java.io.*;
 2 import java.util.*;
 3 import java.math.*;
 4 //import java.text.*;
 5 
 6 public class Main {
 7 
 8     /**
 9      * @param args
10      */
11     public static void main(String[] args) throws Exception{
12         // TODO Auto-generated method stub
13         Scanner cin = new Scanner (System.in);
14         PrintWriter cout = new PrintWriter(System.out);
15         
16         int n = cin.nextInt();
17         BigInteger ans = BigInteger.ONE;
18         for(int i=1;i<=n;i++)
19             ans = ans.multiply(BigInteger.valueOf(i));
20         cout.println(ans);
21         cout.flush();
22     }
23 
24 }

比较大小

题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=73

 1 import java.io.*;
 2 import java.util.*;
 3 import java.math.*;
 4 import java.text.*;
 5 
 6 public class Main {
 7 
 8     /**
 9      * @param args
10      */
11     public static void main(String[] args) {
12         // TODO Auto-generated method stub
13         Scanner cin = new Scanner(System.in);
14         while(true)
15         {
16             BigInteger a = cin.nextBigInteger();
17             BigInteger b = cin.nextBigInteger();
18             if(a.equals(BigInteger.ZERO) && b.equals(BigInteger.ZERO) )
19             {
20                 break;
21             }
22             int flag = a.compareTo(b);
23             if(flag == 0)
24                 System.out.println("a==b");
25             else if(flag == -1)
26                 System.out.println("a<b");
27             else 
28                 System.out.println("a>b");
29         }
30     }
31 
32 }

 

大数加法

题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=103

 1 import java.io.*;
 2 import java.util.*;
 3 import java.math.*;
 4 
 5 
 6 public class Main {
 7 
 8     /**
 9      * @param args
10      */
11     public static void main(String[] args) {
12         // TODO Auto-generated method stub
13             Scanner cin = new Scanner(System.in);
14             int T = cin.nextInt();
15             int cas = 1;
16             for(int i=1;i<=T;i++)
17             {
18                 BigInteger a = cin.nextBigInteger();
19                 BigInteger b = cin.nextBigInteger();
20                 BigInteger ans = a.add(b);
21                 
22                 System.out.println("Case "+i+":");
23                 System.out.println(a+" + "+b+" = "+ans);
24             }
25     }
26 
27 }

 

转载于:https://www.cnblogs.com/helica/p/5242583.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值