[英]Program not determining if the string is a palindrome
having a slight issue with my program for class. 我的上课程序有轻微问题。 the program should determine if the string the user inputs is a palindrome or not, the program itself can determine if a simple string like, "aba" is a palindrome but when the user inputs something such as, "one, two, three, two, one" it automatically declares it as not a palindrome. 程序应该确定用户输入的字符串是否是回文,程序本身可以确定诸如“ aba”之类的简单字符串是否是回文,但是当用户输入“一,二,三,二”时,一个”会自动将其声明为不是回文。 This program is in java, just wondering what i could change to allow the program to be able to read strings such as the second one. 这个程序是用Java编写的,只是想知道我可以更改什么以使该程序能够读取第二个这样的字符串。
import java.util.*;
class Palindrome
{
public static void main(String args[])
{
String original, reverse="";
Scanner in = new Scanner(System.in);
System.out.println("Enter a string to check if it is a palindrome");
original = in.nextLine();
int length = original.length();
for ( int i = length - 1 ; i >= 0 ; i-- )
reverse = reverse + original.charAt(i);
if (original.equals(reverse))
System.out.println("Yo! That is a palindrome.");
else
System.out.println("No! That is not a palindrome.");
}
}
This is the code i'm working with at the moment. 这是我目前正在使用的代码。
您尝试过的字符串不是回文。.回文就像夫人一样,当您反转所有字母时,单词保持不变
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.