public class reverserapp {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("Please Enter a word");
String str = scan.nextLine();
String reverse = "";
for(int i = str.length() - 1; i >= 0; i--)
reverse += str.charAt(i);
if(reverse.equalsIgnoreCase(str))
System.out.println("Palindrome");
else System.out.println("Not Palindrome");
}
}
这是我的回文代码。我正在做这个小任务。我可以得到单个单词的工作,但如果我写了一个像“不点头”的东西,它显示为不回文。我怎样才能做到这一点?我想让我的代码忽略标点符号和空格。如何摆脱回文(Java)的空白
所以最终结果应该是像“dontnod”
在此先感谢您的帮助,完整的小白在此。
怎么样先过滤出来? –
使用正则表达式删除所有空格和其他字符,如%$ @ $#^ * – Omore