Catherine_zhilin

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

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^6<a,b>10^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 package pat;
 2 
 3 import java.util.Scanner;
 4 
 5 public class Main {
 6     private static Scanner sc;
 7     
 8     public static void main (String args[]) {
 9         int a ;
10         int b;
11         int sum;
12         sc=new Scanner (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<Ssum1.length();i++)
23         {
24             //遍历sum结果的所有字符
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

 

posted on 2019-03-02 08:40  kkkshiki  阅读(311)  评论(0编辑  收藏  举报