백준1259

hong030·2023년 2월 9일
0

*solved.ac 기준 브론즈 1단계 문제


풀이)
0을 받기 전까진 계속 입력을 받으므로 while true 문을 사용한다.
펠린드롬 수란 문자의 각 위치를 비교해야 하므로 인덱스 비교가 쉽게 string 그대로 조작한다.

내 코드)

import java.io.*;
public class Backjoon1259 {
	public static void main(String[]args) throws IOException{
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		while(true) {
			String num = bf.readLine();
			if(num.equals("0"))
				break;
			boolean flag = true;
			for(int i =0;i<num.length()/2;i++) {
				if(num.charAt(i) != num.charAt(num.length()-i-1)) {
					flag = false;
					break;}
				else continue;
			}
			if(flag) System.out.println("yes");
			else System.out.println("no");
		}
	}
}

profile
자바 주력, 프론트 공부 중인 초보 개발자. / https://github.com/hongjaewonP

0개의 댓글