PAT甲级练习1001. A+B Format (20)
来源:互联网 发布:无人机编程教材 编辑:程序博客网 时间:2024/06/05 14:47
1001. A+B Format (20)
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 9Sample Output
-999,991
import java.util.Scanner;public class Main {public static void main(String[] args) {int a,b,c;Scanner s = new Scanner(System.in);a = s.nextInt();b = s.nextInt();c = a + b;System.out.printf("%,d", c);}}
Scanner类:
1. 导入import java.util.Scanner;
2. 实用API
delimiter()
返回此 Scanner 当前正在用于匹配分隔符的 Pattern
hasNext()
判断扫描器中当前扫描位置后是否还存在下一段
hasNextLine()
如果在此扫描器的输入中存在另一行,则返回 true
next()
输入一个不含空格的字符串
nextInt()
输入一个整数
s.nextDouble()
输入一个double
s.nextByte()
输入一个字符
nextLine()
此扫描器执行当前行,并返回跳过的输入信息
System.out.printf("%+8.3f\n", 3.14); //"+"表示后面输出的数字会有正负号,正的+,负的- ;8.3f表示输出浮点数,宽度为8,小数点保持3位有效 System.out.printf("%+-8.3f\n", 3.14);//"-"表示靠左对齐 System.out.printf("%08.3f\n", 3.14);//"0"8位宽度中自动补0 System.out.printf("%(8.3f\n", -3.14);//"("如果是负数,自动加上( ) System.out.printf("%,f\n", 123456.78); //","金钱表示方法,每三位有一个逗号 System.out.printf("%x\n", 0x2a3b); //输出16进制数 System.out.printf("%#x\n", 0x2a3b);//输出带0x标识的16进制数 System.out.printf("老板:您名字%s,年龄:%3d岁,工资:%,-7.2f\n","ajioy",21,36000.00); System.out.printf("老板:您名字%1$s,年龄:%2$#x岁\n","ajioy",38); //"n{1}quot;表示用第n个参数
- PAT甲级练习1001. A+B Format (20)
- PAT甲级1001. A+B Format (20)
- PAT甲级.1001. A+B Format (20)
- 【PAT甲级】1001. A+B Format (20)
- PAT甲级 1001. A+B Format (20)
- PAT甲级1001. A+B Format (20)
- PAT甲级 1001. A+B Format (20)
- PAT甲级1001. A+B Format (20)
- PAT甲级1001. A+B Format (20)
- PAT 甲级1001. A+B Format (20)
- PAT甲级1001. A + B Format(20)
- PAT甲级 1001. A+B Format
- 1001. A+B Format-PAT甲级
- [PAT-甲级]1001.A+B Format
- PAT 甲级 1001. A+B Format
- PAT甲级1001. A+B Format
- PAT 甲级 1001. A+B Format
- PAT甲级1001. A+B Format(20)
- 使用EditPlus打造一个Python IDE
- 谷歌官网的Volley网络框架实战②--ImageRequest、ImageLoader、NetworkImageView加载图片
- ios 随机数
- 杭电 2031 ( 进制转换 ) java
- angular controller错误
- PAT甲级练习1001. A+B Format (20)
- python logging 模块
- play之入门篇
- linux 安装 RabbitMQ
- redis的安装与使用(单机)
- 【知识】Miracast
- 杭电 2032 ( 杨辉三角 ) java
- Jenkins+Gitlab+Sonar代码检查平台搭建-java_maven项目
- CentOS7 Hadoop2.7.3 安装HBase