pat 1001 java_PAT(甲级)Practice1001--Java版

1001 A+BFromat

Calculate a+b and output the sum in standard format -- that is,the diits must be seperated into groups of three commas (unless there are less than for digits).

Input Spercification :

Each input file contians one test case.Each case contains a pair of integers a and b where -10^610^6 .The numbers are sparated 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

8f900a89c6347c561fdf2122f13be562.png

961ddebeb323a10fe0623af514929fc1.png

1 packagepat;2

3 importjava.util.Scanner;4

5 public classMain {6 private staticScanner sc;7

8 public static voidmain (String args[]) {9 inta ;10 intb;11 intsum;12 sc=newScanner (System.in);13 a=sc.nextInt();14 b=sc.nextInt();15 sc.close();16 sum =a+b;17 String Ssum1=""+sum;18 //String Ssum2=String.valueOf(sum);

19 System.out.println(Ssum1.length());20 //System.out.println(Ssum2.length());21 //System.out.println(Ssum1.substring(0,Ssum1.length()));

22 for(int i=0;i

25 System.out.print(Ssum1.substring(i,i+1));26 //在已得到的结果上加上逗号27 //if("-".equals(Ssum1.substring(i,i+1)))28 //continue;

29 if((i+1)%3==Ssum1.length()%3 && i!=Ssum1.length()-1)30 System.out.print(",");31

32 }33 }34

35 }

View Code

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值