본문 바로가기

프로그래머스 코딩(자바)/Coding dojang

palindrome

728x90

앞에서부터 읽을 때나 뒤에서부터 읽을 때나

모양이 같은 수를 대칭수(palindrome)라고 부릅니다.

두 자리 수를 곱해 만들 수 있는 대칭수 중 가장 큰 수는 9009 (= 91 × 99) 입니다.

세 자리 수를 곱해 만들 수 있는 가장 큰 대칭수는 얼마입니까?

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
public class Exam0406_2 {
    public static void main(String[] args) {
        System.out.println(solution());
    }
    
    public static int solution() {
        int result = 0;
        for(int i=999;i>=10;i--) {
            for(int j=999;j>=10;j--) {
                String str1 = i*j+"";
                String str2 = new StringBuilder(str1).reverse().toString();
                if(str1.length()%2==0 && str1.equals(str2)) {
                    result = Math.max(i*j,result);
                }
            }
        }
        return result;
    }
}
 
cs

 

 

728x90