1001 A+B Format (20 分)
Calculate a+b and output the sum in standard format -- that is, the digits must be separated into groups of three by commas (unless there are less than four digits).
Input Specification:
Each input file contains one test case. Each case contains a pair of integers a and b where −106≤a,b≤106. The numbers are separated by a space.
Output Specification:
For each test case, you should output the sum of a and b in one line. The sum must be written in the standard format.
Sample Input:
-1000000 9
Sample Output:
-999,991
代码示例:
1 import java.util.Scanner; 2 /** 3 * @Auther: Xingzheng Wang 4 * @Date: 2019/1/17 10:06 5 * @Description: pattest 6 * @Version: 1.0 7 */ 8 public class PAT1001 { 9 public static void main(String[] args){ 10 Scanner sc = new Scanner(System.in); 11 int a = sc.nextInt(); 12 int b = sc.nextInt(); 13 System.out.printf("%,d",a+b); 14 } 15 }
本文详细解析了PAT1001A+BFormat题目的要求与解决方案,介绍了如何使用Java处理大整数相加,并以标准格式输出结果,包括用逗号分隔每三位数字。
Java&spm=1001.2101.3001.5002&articleId=101581062&d=1&t=3&u=5dfd161353bb4237af7ee5eaca9a2f72)
333

被折叠的 条评论
为什么被折叠?



