1.代码
package com.rfg.javabasics.string;
/**
* @Author: RuanFuGui
* @Date: Created in 2020/6/8 15:25
* @Description: 字符串使用练习
* @Version: 1.0
*/
public class StringTest {
public static void main(String[] args) {
String s = "abcdcba";
boolean judgeResult = new StringTest().judje(s);
if(judgeResult){
System.out.println("是回文数");
}else{
System.out.println("不是回文数");
}
}
public boolean judje(String s){
int length = s.length();
boolean judgeResult = true;
for(int i=0;i<length/2;i++) {
if(s.charAt(i)==s.charAt(length-1-i)){
judgeResult = true;
}else{
judgeResult = false;
break;
}
}
return judgeResult;
}
}