java:判断字符串是不是回文字符串

import java.util.*;
public class forth2 {
	public static void main(String[] args) {
		Scanner input =new Scanner(System.in);
		System.out.print("enter a string: ");
		String s=input.nextLine();
		int low =0;
		int high=s.length()-1;
		boolean isp=true;
		while(low<high)
		{
			if(s.charAt(low)!=s.charAt(high))
			{
				isp=false;
				break;
			}
			low++;
			high--;
		}
			if(isp)
			System.out.println(s +"is a palindrome");
		else
			System.out.println(s +"is not");
	}

}

猜你喜欢

转载自blog.csdn.net/j_linlian/article/details/79672172
今日推荐