1001. A+B Format (20)---------------PAT开始

今天是第一次用Java提交PAT的代码:

源代码不能直接提交,需要经过修改:

源代码:

 1 package test;//提交时不能显示这句
 2 
 3 import java.util.Scanner;
 4 
 5 public class Test_1001 {//提交时名字要改成Main
 6     public static void main(String[] args) {
 7         Scanner inScanner =new Scanner(System.in);
 8         long a=inScanner.nextLong();
 9         long b=inScanner.nextLong();
10         long c=a+b;
11         if(c<0){
12             System.out.print("-");
13             c=0-c;
14         }
15         String s=String.valueOf(c);
16         String out="";
17         int count=0;
18         for(int i=s.length()-1;i>=0;i--){
19             out=s.charAt(i)+out;
20             count++;
21             if(count%3==0&&i!=0){
22                 count=0;
23                 out=","+out;
24             }
25             
26         }
27         System.out.println(out);
28     }
29 
30 }

 

posted @ 2017-05-06 21:07  贱人郭  阅读(105)  评论(0编辑  收藏  举报