Java Output Formatting
来源:互联网 发布:元级潜艇模型 淘宝 编辑:程序博客网 时间:2024/06/10 05:18
% - 0 m.n l或h 格式字符
下面对组成格式说明的各项加以说明:
①%:表示格式说明的起始符号,不可缺少。
②-:有-表示左对齐输出,如省略表示右对齐输出。
③0:有0表示指定空位填0,如省略表示指定空位不填。
④m.n:m指域宽,即对应的输出项在输出设备上所占的字符数。N指精度。用于说明输出的实型数的小数位数。为指定n时,隐含的精度为n=6位。
⑤l或h:l对整型指long型,对实型指double型。h用于将整型的格式字符修正为short型。
Sample Input
java 100cpp 65python 50
Sample Output
================================java 100 cpp 065 python 050 ================================
Explanation
Each String is left-justified with trailing whitespace through the first characters. The leading digit of the integer is the character, and each integer that was less than digits now has leading zeroes.
import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("================================");
for(int i=0;i<3;i++)
{
String s1=sc.next();
int x=sc.nextInt();
//Complete this line
System.out.printf("%-15s", s1);
System.out.printf("%03d", x);
System.out.println();
}
System.out.println("================================");
}
}
- Java Output Formatting
- [Python]Input/Output and str Formatting
- Formatting
- Java Code Output
- Java Input/Output API
- Java Output Format
- Java for Complete Beginners StringBuilder and String Formatting
- A Simple Java Tree Output
- input & output in Java demo
- JAVA学习分享Input Output
- java IO接口(output)
- output
- Output
- output
- Output
- formatting messagebox
- Formatting Types
- Formatting Types
- 第一期资料
- Min Max Roads(树剖+线段树)
- C# Winform控件贴透明png图片遇到的问题
- Apache mina2 用户指南(十四)状态机
- C语言(10)------逻辑运算符
- Java Output Formatting
- XMLHttpRequest的下一代fetch
- 学习FFmpeg API – 解码视频
- 任意字节对齐的内存分配和释放
- HDU:2571 命运(DP)
- Java网络编程(四) 通过MulticastSocket实现广播
- Apache mina2 用户指南(十三)调试
- 使用Zip Utils 解压文件的操作示例
- Gecco源码分析(一)