JAVA基础操作
1. 大数类型的读入
Scanner in = new Scanner ( System. in) ;
BigInteger n = in. nextBigInteger ( ) ;
2. 字符串类型的读入
String a = in. next ( ) ;
3. 将一个n进制下的a转化成十进制下的大数x
BigInteger x = new BigInteger ( a, n) ;
4. 大数加减乘除
大数+
x = x. add ( y) ;
大数-
y = y. negate ( ) ;
x = x. add ( y) ;
大数*
x = x. multiply ( y) ;
大数/
x = x. divide ( y) ;
5. 将字符串s所有的英文字母转化为大写输出
System. out. println ( s. toUpperCase ( ) ) ;
6. 定义数组
public static boolean prime[ ] = new boolean [ 1000 ] ;
public static int primenum[ ] = new int [ 1000 ] ;
7. 一个大数类型x和int 类型n的大小判断
if ( x. compareTo ( n) > 0 )
8. 将一个int 类型赋值给一个大数类型
int x;
BigInteger y = BigInteger. valueOf ( x) ;
9. 含字符串输出(自带换行, + 号连接)
System. out. println ( x + "/" + y) ;
10. gcd
BigInteger x, y;
BigInteger g = x. gcd ( y) ;
最终模板
import java. math. BigInteger;
import java. util. Scanner;
public class Main
{
public static int xxx[ ] = new int [ 1000 ] ;
public static void main ( String[ ] args)
{
Scanner in = new Scanner ( System. in) ;
}
}