Java-SDUT1250 回文串判定

版权声明:iQXQZX https://blog.csdn.net/Cherishlife_/article/details/85227133

回文串判定

Time Limit: 1000 ms Memory Limit: 65536 KiB

Submit Statistic

Problem Description

输入一串字符(长度小于100),判断该串字符是否是回文串(正序读与逆序读内容相同)。

Input

输入一串字符(长度小于100)。

Output

若该串字符是回文串输出“yes",否则输出”no“。

Sample Input

asdfgfdsa

Sample Output

yes

Hint

Source

ACcode:

import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String s1;
		s1 = in.nextLine();
		int i = 0, j = s1.length() - 1;
		int flag = 0;
		while (true) {
			if (s1.charAt(i) != s1.charAt(j)) {  // charAt.()方法 字符串索引
				flag = 1;
				break;
			} else {
				i++;
				j--;
				if (i >= j)
					break;
			}
		}
		if (flag == 0)
			System.out.println("yes");
		else
			System.out.println("no");
	}
}

猜你喜欢

转载自blog.csdn.net/Cherishlife_/article/details/85227133