展开全部
这种是利用数组。 字符串反转比较。
*****************************************************************
import java.io.*;
public class HuiWen {
String reverse(String w1) {
String w2;
char []str1 = w1.toCharArray();
int len = w1.length();
char []str2 = new char[len];
for(int i = 0; i<len; i++) {
str2[i] = str1[len - 1 -i];
}
w2 = new String(str2);
return w2;
}
public static void main(String args[]) {
HuiWen hw1 = new HuiWen();
String pm ="";
try {
InputStreamReader Reader = new InputStreamReader(System.in);
BufferedReader input = new BufferedReader(Reader);
System.out.print("give your test String :\n");
pm = input.readLine();
}catch(IOException e) {
System.out.println("exception occur..");
}
String w2 = hw1.reverse(pm);
if(w2.compareTo(pm) == 0) {
System.out.println("It is a HuiWen");
}
else {
System.out.println("It is not a HuiWen");
}
}
}
*****************************************************************
import java.io.*;
public class HuiWen {
String reverse(String w1) {
String w2;
char []str1 = w1.toCharArray();
int len = w1.length();
char []str2 = new char[len];
for(int i = 0; i<len; i++) {
str2[i] = str1[len - 1 -i];
}
w2 = new String(str2);
return w2;
}
public static void main(String args[]) {
HuiWen hw1 = new HuiWen();
String pm ="";
try {
InputStreamReader Reader = new InputStreamReader(System.in);
BufferedReader input = new BufferedReader(Reader);
System.out.print("give your test String :\n");
pm = input.readLine();
}catch(IOException e) {
System.out.println("exception occur..");
}
String w2 = hw1.reverse(pm);
if(w2.compareTo(pm) == 0) {
System.out.println("It is a HuiWen");
}
else {
System.out.println("It is not a HuiWen");
}
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
import java.util.*;
public class TestChar {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Input your word!");
String str = sc.nextLine();
if(isMatch(str)) {
System.out.println("is Match!");
} else
System.out.println("is not Match!");
}
static public boolean isMatch(String str) {
boolean b = true;
int len=str.length();
for(int i=0;i<len/2;i++) {
if( str.charAt(i)==str.charAt(len-i-1) )
continue;
else b = false;
return b;
}
return b;
}
}
public class TestChar {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Input your word!");
String str = sc.nextLine();
if(isMatch(str)) {
System.out.println("is Match!");
} else
System.out.println("is not Match!");
}
static public boolean isMatch(String str) {
boolean b = true;
int len=str.length();
for(int i=0;i<len/2;i++) {
if( str.charAt(i)==str.charAt(len-i-1) )
continue;
else b = false;
return b;
}
return b;
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询