到底是錯在哪裡?
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String str;
char[] strASCII;
boolean count;
//String temp0 = ""; //將 temp 清空
String com1;
String com2;
while(input.hasNext()){
count = true;
str = input.nextLine(); //輸入字串
strASCII = new char[str.length()]; //產生新的陣列
String temp0 = str.replaceAll("\\W","");
String temp1 = temp0.replaceAll("_","");
String temp = temp1.toLowerCase();
com1 = "";
com2 = "";
for(int i = 0 ; i < temp.length() / 2 ; i++) //分開字串,準備比較
com1 += temp.charAt(i);
if(temp.length() % 2 == 0)
for(int i = temp.length()-1 ; i >= temp.length() / 2 ; i--)
com2 += temp.charAt(i);
else
for(int i = temp.length()-1 ; i > temp.length() / 2 ; i--)
com2 += temp.charAt(i);
int n = com1.length();
//分開字串結束
for(int i = 0 ; i < n/2 ;i++){
if(com1.charAt(i)-com2.charAt(i) == com1.charAt(n-1-i) - com2.charAt(n-1-i))
count = true;
else
{
count = false;
break;
}
}
if(count == true) //比較並輸出
System.out.println("yes !");
else
System.out.println("no...");
} //while 結尾
}
}