[첫번째 생각]
각 단어별로 받아서 역순 취해주고 정수로 바꿔서 비교해주자.
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String[] str = sc.nextLine().trim().split(" ");
String temp = "";
for(int i = str[0].length() - 1; i >= 0; i--) {
temp += str[0].charAt(i);
}
str[0] = temp;
temp = "";
for(int i = str[1].length() - 1; i >= 0; i--) {
temp += str[1].charAt(i);
}
str[1] = temp;
int x = Integer.parseInt(str[0]);
int y = Integer.parseInt(str[1]);
if(x > y) {
System.out.println(x);
} else System.out.println(y);
}
}
[문제점 발생]
[두번째 생각]
[훨씬 쉬운 코드]
[결론]
String temp = "";
for(int i = str[0].length() - 1; i >= 0; i--) {
temp += str[0].charAt(i);
}
str[0] = temp;
역순으로 바꿔주는 코드
'이제는 사용하지 않는 공부방 > Algorithm' 카테고리의 다른 글
백준 8단계 크로아티아알파벳 자바 (0) | 2020.04.18 |
---|---|
백준 8단계 다이얼 자바 (0) | 2020.04.18 |
백준 8단계 단어의 개수 (0) | 2020.04.18 |
백준 8단계 문자열 반복 (0) | 2020.04.16 |
백준 8단계 알파벳찾기 (2) | 2020.04.16 |