make it simple
article thumbnail

문제: 앞에서 읽을 때나 뒤에서 읽을 때나 같은 문자열인지 확인하세요. 같은 무자열이면 YES 아니면 NO를 출력하세요.

예제) sooS  -> YES

       dooE  -> NO

 

	public static void main(String[] args) {
		problem7 prob = new problem7();
		Scanner sc = new Scanner(System.in);

		String word = sc.nextLine();
		if(prob.solution(word).equals(word.toLowerCase())) {  // 다 소문자로 바꾼후 앞에 단어랑 맞는지 안 맞는지 조건문
			System.out.println("YES");
		}else {
			System.out.println("NO");
		}
	}


	public String solution(String word) {
		String ans ="";
		word = word.toLowerCase();
		char[] arr = word.toCharArray();

		for(int i=arr.length-1; i>=0; i--) {
			ans += arr[i];
		}
		return ans;
	}

실행결과 성공!

입력: sooS

출력: YES

profile

make it simple

@keep it simple

포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!