判断是否为回文串

package com.lkr.dataStructure;

import java.util.Scanner;

public class HuiwenString {
public static void main(String[] args){
System.out.println("请输入字符串");
Scanner input = new Scanner(System.in);
String s = input.next();
boolean isHuiWen = isHuiwen(s);
if(isHuiWen){
System.out.println(s + "是回文串");
}
else System.out.println(s + "不是回文串");
}
public static boolean isHuiwen(String text){
int length = text.length();
for(int i=0;i<length/2;i++){
if(text.toCharArray()[i] != text.toCharArray()[length-i-1]){
return false;
}

}
return true;

}
}
posted @ 2019-02-20 04:29  图图图图胡图图  阅读(267)  评论(0编辑  收藏  举报