[PAT] 1001 A+B Format (20 分)Java

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,b106​​. 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 }
 




猜你喜欢

转载自www.cnblogs.com/PureJava/p/10497897.html
今日推荐