forked from natural/java2python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFormat1.java
More file actions
19 lines (16 loc) · 716 Bytes
/
Format1.java
File metadata and controls
19 lines (16 loc) · 716 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
public class Format1 {
public static void main(String[] args) {
long n = 461012;
String f1 = String.format("%d%n", n); // --> "461012"
String f2 = String.format("%08d%n", n); // --> "00461012"
String f3 = String.format("%+8d%n", n); // --> " +461012"
String f4 = String.format("%,8d%n", n); // --> " 461,012"
String f5 = String.format("%+,8d%n", n); // --> "+461,012"
System.out.println(f1 + f2 + f3 + f4 + f5);
double pi = 3.14159265;
String pf1 = String.format("%f%n", pi); // --> "3.141593"
String pf2 = String.format("%.3f%n", pi); // --> "3.142"
String pf3 = String.format("%10.3f%n", pi); // --> " 3.142"
System.out.println(pf1 + pf2 + pf3);
}
}