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");
	}

}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章