do_it0904 2022. 12. 6. 13:49
/* 편지
 * 할머니가 보시기 편하도록 글자 한 자 한 자를 가로 2cm 크기로 적으려고 하며,
 * 편지를 가로로만 적을 때, 축하 문구 message를 적기 위해 필요한
 * 편지지의 최소 가로길이를 return 하도록 solution 함수를 완성해주세요.
 *
 * message              result
 * "happy birthday!"    30      글자 수가 15개로 최소 가로 30cm의 편지지
 * "I love you~"        22      글자 수가 11개로 최소 가로 22cm의 편지지
 */
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
public class programmer_0_19 {
    static String a1 = "happy birthday!";
    static String a2 = "I love you~";
 
    public int solution(String message) {
        int answer = 0;
        
        return message.length()*2;
    }
    public static void main(String args[]){
        programmer_0_19 t = new programmer_0_19();
        System.out.println("---------------------------------------");
        System.out.println("result = " + t.solution(a1));
        System.out.println("---------------------------------------");
        System.out.println("result = " + t.solution(a2));
        System.out.println("---------------------------------------");
    }
}
cs