-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinputOutput.java
More file actions
45 lines (38 loc) · 1.6 KB
/
inputOutput.java
File metadata and controls
45 lines (38 loc) · 1.6 KB
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
41
42
43
44
45
import java.io.*;
import java.util.*;
import java.text.DecimalFormat;
public class Main {
public static void main(String[] args) throws IOException {
// 입력 세팅
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;
// 예: 정수 N, 그리고 공백 구분된 숫자 두 개 읽기
st = new StringTokenizer(br.readLine());
int N = Integer.parseInt(st.nextToken());
double x = Double.parseDouble(st.nextToken());
double y = Double.parseDouble(st.nextToken());
// 문자열 결과 조합용 StringBuilder
StringBuilder sb = new StringBuilder();
// 예: N번 반복 입력 처리
for (int i = 0; i < N; i++) {
st = new StringTokenizer(br.readLine());
int a = Integer.parseInt(st.nextToken());
int b = Integer.parseInt(st.nextToken());
double sum = a + b;
sb.append(sum).append('\n');
}
// 소수점 포맷: 소수점 둘째 자리까지
// 방법 A: String.format
String formatted = String.format(Locale.US, "%.2f", x / y);
sb.append("Formatted by String.format: ").append(formatted).append('\n');
// 방법 B: DecimalFormat
DecimalFormat df = new DecimalFormat("#.##");
sb.append("Formatted by DecimalFormat: ").append(df.format(x / y)).append('\n');
// 출력 세팅
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
bw.write(sb.toString());
bw.flush();
bw.close();
br.close();
}
}