往下看之前需要知道的,关于Java的一、东西

点我查看更多
多组输入:while(cin.hasNextInt())
int与BigInteger计算先变一下
大数赋值:BigInteger.valueOf(数);
A+B问题

import java.io.*;
import java.util.*;
import java.math.*;
import java.text.*;
public class Main
{
	public static void main(String[] args)
	{
		Scanner cin=new Scanner(System.in);
		int t;
		t=cin.nextInt();
		for(int i=1;i<=t;++i)
		{
			if(i!=t)
			{
				BigInteger a,b;
				BigInteger sum=BigInteger.ZERO;
				a=cin.nextBigInteger();
				b=cin.nextBigInteger();
				sum=sum.add(a);
				sum=sum.add(b);
				System.out.println("Case "+i+":");
				System.out.println(a+" + "+b+" = "+sum);
				System.out.println();
			}
			else
			{
				BigInteger a,b;
				BigInteger sum=BigInteger.ZERO;
				a=cin.nextBigInteger();
				b=cin.nextBigInteger();
				sum=sum.add(a);
				sum=sum.add(b);
				System.out.println("Case "+i+":");
				System.out.println(a+" + "+b+" = "+sum);
			}
		}
	}
}

N!

import java.io.*;
import java.util.*;
import java.math.*;
import java.text.*;
public class Main
{
	public static void main(String[] args)
	{
		Scanner cin=new Scanner(System.in);
		int n;
		while(cin.hasNextInt())
		{
			n=cin.nextInt();
			BigInteger sum=BigInteger.valueOf(1);
			for(int i=1;i<=n;++i)
			{
				BigInteger a=BigInteger.valueOf(i);
				sum=sum.multiply(a);
			}
			System.out.println(sum);
		}
	}
}