JAVA/백준
백준 2908번 - 상수
수e
2022. 3. 22. 01:10
아무것도 모르고 짠 내 코드..
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
|
public class Main {
public static void div(int a, int b) throws IOException {
BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(System.out));
if(a>b) {
bw.write(a);
}else if(a<b) {
bw.write(b);
}
bw.flush();
bw.close();
}
public static void main(String[] args) throws IOException {
BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
String a=bf.readLine();
int first=Character.getNumericValue(a.charAt(2))*100+Character.getNumericValue(a.charAt(1))*10
+Character.getNumericValue(a.charAt(0))*1;
String b=bf.readLine();
int second=Character.getNumericValue(b.charAt(2))*100+Character.getNumericValue(b.charAt(1))*10
+Character.getNumericValue(b.charAt(0))*1;
div(first, second);
}
}
|
c |
응 런타임 에러
수업에서 쪼꼼 배운 라이브러리로는 커버하기가 점점 힘들어지고 있는 것이다..책으로 공부해야 할 때인가?
- StringTokenizer, StringBuilder 로 간결하게 짜기(참고 : https://st-lab.tistory.com/66)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
public class Main {
public static void div(int a, int b) {
if(a>b) {
System.out.println(a);
}else if(a<b) {
System.out.println(b);
}
}
public static void main(String[] args) throws IOException {
BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
String a=bf.readLine();
StringTokenizer st=new StringTokenizer(a, " ");
int first=Integer.parseInt(new StringBuilder(st.nextToken()).reverse().toString());
int second=Integer.parseInt(new StringBuilder(st.nextToken()).reverse().toString());
div(first, second);
}
}
|
cs |