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);
}
}