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. 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.
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.
您尝试过的字符串不是回文。.回文就像夫人一样,当您反转所有字母时,单词保持不变
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.