[프로그래머스] Lv.0 접두사인지 확인하기.java

hgghfgf·2023년 6월 1일
0

프로그래머스

목록 보기
110/227

class Solution {
    public int solution(String my_string, String is_prefix) {
        if(my_string.startsWith(is_prefix)){
            return 1;
        }else{
            return 0;
        }
    }
}

startsWith 메서드는 주어진 문자열이 다른 문자열로 시작하는 여부를 확인하는 메서드
boolean startsWith(String prefix)
예시)
String str1 = "Hello, world!";
boolean startsWithHello = str1.startsWith("Hello"); // true
boolean startsWithWorld = str1.startsWith("world!"); // false

String str2 = "abcdefg";
boolean startsWithABC = str2.startsWith("ABC"); // false
boolean startsWithA = str2.startsWith("a"); // true

출처: 프로그래머스 코딩 테스트 연습, https://school.programmers.co.kr/learn/challenges

0개의 댓글