-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFormat.java
More file actions
40 lines (34 loc) · 880 Bytes
/
Format.java
File metadata and controls
40 lines (34 loc) · 880 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package Base;
import java.io.BufferedReader;
import java.io.StringReader;
import java.util.Formatter;
import java.util.Scanner;
public class Format {
private static Formatter f = new Formatter(System.out);
public static void main(String[] args) {
String str = "haoge";
int a = 100, c = 1000;
// 1
System.out.format("%s %d\n%d\n", str, a, c);
// 2
// f.format("%s %d\n%d", str,a,c);
f.format("%s\n%-10d\n%-10d", str, a, c);
// 3
Scanner in = new Scanner(System.in);
while (in.hasNext()) {
int e = in.nextInt(), f = in.nextInt();
double g = in.nextDouble();
System.out.format("%d %d %f", e, f, g);
}
in.close();
BufferedReader reader = new BufferedReader(new StringReader(
"a,b\n,c,d\n"));
try {
while (reader.readLine() != null) {
System.out.println(reader.read());
}
reader.close();
} catch (Exception e) {
}
}
}