Hi, I am working on a java program for my class where I have to rewrite a code that checks whether the input is a palindrom by passing the string as a command-line argument.
Here is the code that I have to rewrite. PLEASE HELP!!
Here is the code that I have to rewrite. PLEASE HELP!!
Code:
import javax.swing.JOptionPane;
public class CheckPalindrome
{
public static void main(String [] args)
{
String s = JOptionPane.showInputDialog("Enter a string");
String output = "";
if(isPalindrome(s))
output = s + " is a palindrome.";
else
output = s + " is not a palindrome.";
JOptionPane.showMessageDialog(null, output);
}
public static boolean isPalindrome(String s)
{
int low = 0;
int high = s.length() - 1;
while(low < high)
{
if(s.charAt(low) != s,charAt(high))
return false;
low++;
high--;
}
return true;
}
}
Comment