inblog logo
|
muaga's Hub
    Programmers-Java

    [프로그래머스] Lv.0 짝수는 싫어요 (배열의 값 추가)

    [프로그래머스] Lv.0 짝수는 싫어요 (배열의 값 추가)
    muaga's avatar
    muaga
    May 08, 2024
    [프로그래머스] Lv.0  짝수는 싫어요 (배열의 값 추가)
    Contents
    답
    notion image
    notion image
     

    답


    ◽ 배열

    class Solution { public String solution(String cipher, int code) { // 문자열 -> 배열로 char[] cipherArr = cipher.toCharArray(); // 번째 갯수 int count = cipher.length() / code; // 해독된 암호 String answer = ""; for (int a = 1; a <= count; a++) { int num = code * a; char word = cipherArr[num - 1]; answer = answer + word; } return answer; } }
     

    ◽ substring( )

    class Solution { public String solution(String cipher, int code) { // 번째 갯수 int count = cipher.length() / code; // 해독된 암호 String answer = ""; for (int a = 1; a <= count; a++) { int num = code * a; String word = cipher.substring((num - 1), num); // 시작 index, 끝 index answer = answer + word; } return answer; } }
     
     
    Share article
    Contents
    답

    muaga's Hub

    RSS·Powered by Inblog