Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Rewrite the CheckingPalindrome program by passing the string as a comm

ryclegmanryclegman Posts: 16Member
Rewrite the CheckingPalindrome program by passing the string as a command-line argument. Please help because i quite frankly dont understand... What parts do i have to change and where? thanks a ton guys![code]import javax.swing.JOptionPane;

public class CheckPalindrome {
/** Main method */
public static void main(String[] args) {
// Prompt the user to enter a string
String s = JOptionPane.showInputDialog(null,
"Enter a string:", "Example 7.1 Input",

// Declare and initialize output string
String output = "";

if (isPalindrome(s))
output += s + " is a palindrome";
output += s + " is not a palindrome";

// Display the result
JOptionPane.showMessageDialog(null, output,
"Example 7.1 Output", JOptionPane.INFORMATION_MESSAGE);


/** Check if a string is a palindrome */
public static boolean isPalindrome(String s) {
// The index of the first character in the string
int low = 0;

// The index of the last character in the string
int high = s.length() - 1;

while (low < high) {
if (s.charAt(low) != s.charAt(high))
return false; // Not a palindrome


return true; // The string is a palindrome
Sign In or Register to comment.