package test.HWtest;
import java.util.Scanner;
public class HWString {//判断字符串
public static void hwReverse(String str){//方法一;将字符串倒置后逐一比较,
StringBuffer sb =new StringBuffer(str);
//System.out.println(sb);
sb.reverse();
//System.out.println(sb);
String newStr =new String(sb);
if(str.equals(newStr)){
System.out.println("1是回文");
}
else{
System.out.println("1不是回文");
}
}
public static void hwlength(String str){
StringBuffer sb =new StringBuffer(str);
//System.out.println(sb);
sb.reverse();
//System.out.println(sb);
int count=0;
for(int i=0;i
//数组中有length属性,没有length()方法
if(str.charAt(i)==sb.charAt(i)){
count++;
}
}
if(count == str.length()){
System.out.println("2是回文");
}
else{
System.out.println("2不是回文");
}
}
public static void main(String[] args) { //方法二 将字符串倒置后创建新字符串直接比较,
// TODO Auto-generated method stub
Scanner sc =new Scanner(System.in);
String str ="";
str =sc.nextLine();
hwReverse(str);
hwlength(str);
/*iamai
1是回文
2是回文*/}
}