java学习(9):杭电1002.大数处理问题
import java.math.BigDecimal; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String temp1 = null; String temp2 = null; String result = null; int i; int a = scanner.nextInt(); for (i = 0; i < a; i++) { temp1 = scanner.next(); temp2 = scanner.next(); BigDecimal bigDecimal1 = new BigDecimal(temp1); BigDecimal bigDecimal2 = new BigDecimal(temp2); result = bigDecimal1.add(bigDecimal2).toString(); if (i != (a - 1)) { System.out.println( "Case " + (i + 1) + ":\r\n" + bigDecimal1 + " + " + bigDecimal2 + " = " + result + "\r\n"); }else{ System.out.println( "Case " + (i + 1) + ":\r\n" + bigDecimal1 + " + " + bigDecimal2 + " = " + result); } } } }