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
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