先用字符串将字符串接收,然后在用BigInteger就好了
代码:
import java.util.Scanner; import java.math.*; public class Main{ public static void main(String[] args){ Scanner cin = new Scanner(System.in); while(cin.hasNextBigInteger()){ BigInteger aa, bb; //a = cin.nextBigDecimal(); //b = cin.nextBigDecimal(); String a, b, c; a = cin.next(); b = cin.next(); c = cin.next(); aa = new BigInteger(a); bb = new BigInteger(c); //System.out.println(a); //System.out.println(b); //System.out.println(c); if(b.compareTo("/") == 0) System.out.println(aa.divide(bb)); if(b.compareTo("%") == 0){ System.out.println(aa.mod(bb)); } //else System.out.println("NO"); } } }
原文地址:http://blog.csdn.net/shengweisong/article/details/39105685