博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
PAT 1001. A+B Format (20)
阅读量:4709 次
发布时间:2019-06-10

本文共 1353 字,大约阅读时间需要 4 分钟。

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

Each input file contains one test case. Each case contains a pair of integers a and b where -1000000 <= a, b <= 1000000. The numbers are separated by a space.

 

Output

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  4 public class Main { 5     public static void main(String[] args) { 6         Scanner input = new Scanner(System.in); 7         int a = input.nextInt(); 8         int b = input.nextInt(); 9         int sum = a+b;10         String temp = sum+"";11         if(sum<0){12             if(temp.length()<=4){13                 System.out.println(sum);;14             }else{15                 int m = (temp.length()-1)%3;16                 System.out.print(temp.charAt(0));17                 if(m==1){18                     System.out.print(temp.charAt(1));19                 }20                 if(m==2){21                     System.out.print(temp.charAt(1));22                     System.out.print(temp.charAt(2));23                 }24                 for(int i=m+1;i

 

转载于:https://www.cnblogs.com/lolybj/p/7124231.html

你可能感兴趣的文章
发布和订阅的删除
查看>>
如何使用qtp12 utf进行功能测试
查看>>
使用LinQ进行增删改查
查看>>
关于iOS适配问题
查看>>
C语言博客作业--嵌套循环
查看>>
内部类 ( Inner Class )
查看>>
Linux 使用者 群组 权限
查看>>
【PAT】B1047 编程团体赛(20 分)
查看>>
iPad软件提交注意事项
查看>>
约束和异常处理
查看>>
css 布局
查看>>
RESTful风格化
查看>>
C# 多线程学习系列二
查看>>
如何将你的github仓库部署到github pages(转)
查看>>
几个重要的shell命令:diff patch tar find grep
查看>>
学习笔记
查看>>
JS ES6 -- let命令
查看>>
查找空座位问题
查看>>
几个简单规则改进你的SEO效果
查看>>
UVA10820 Send a Table
查看>>