Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9003269
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:41:27+00:00 2026-06-16T00:41:27+00:00

I am practising a string palindrome. Is my code in my for loop right?

  • 0

I am practising a string palindrome. Is my code in my for loop right?

public static void main (String args[]) 
{
    String word = JOptionPane.showInputDialog("Input a String:");
    String finalword = word.replaceAll(" ","").toLowerCase();

    for (int x = word.length(); x >= word.length()-1; x--) 
    {
        finalword.charAt(x);
    }

    if(word.equals(finalword)) 
    {
        JOptionPane.showMessageDialog(null, "Palindrome");
    }
    else 
    {
        JOptionPane.showMessageDialog(null, "Not a Palindrome");
    }
}    

Thank you and best regards.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T00:41:28+00:00Added an answer on June 16, 2026 at 12:41 am
    1. The actual string you need to work on is finalword as its length important to you.

    2. For simplicity take two temp arrays like tempStart and tempLast, both has to be same length as (finalword.length /2), Dont worry about string has even or odd number of chars.

    3. use for loop with two variables as follows.

       for(int x = 0, y=finalword.length(); x<finalword.length() / 2; x++,y--){
         // check tempStart and tempLast has same chars.
         // I hope you know rule for palindrome.
       }
      
    4. if these both arrays (tempStart and tempLast) matches then its palindrome otherwise not.

    I hope this will help you. If not let me know you need any more help while doing this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am practising from LYAH. phoneBook.hs file contains following code: phoneBook :: [(String, String)]
I've recently started practising TDD and unit testing, with my main primers being the
Hello i'm practising C and i have a little problem with the following code.
I am practicing regex with C#. This is my code: string test = this
I was practising statements and ran into a problem. I'm trying to make it
I was practising the algorithm based programming problem.I am having difficulty,in solving this problem.I
I am once again a bit stuck in my practising. I want an MP3
I am practicing this https://developer.mozilla.org/en/Canvas_tutorial/Basic_animations Clock tutorial. Everything in the code is clear to
Possible Duplicate: Is it possible to modify a string of char in C? #include
I am practising '[ and '] , and I cannot see the difference. How

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.