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 8611911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:29:37+00:00 2026-06-12T04:29:37+00:00

I need to write a program that gets a string from the user and

  • 0

I need to write a program that gets a string from the user and tests to see if it’s a palindrome. This has to be done with nested loops: I can’t write a method to return the answer. I also have to keep accepting string inputs and testing them until the user enters an empty line, at which point the program prints ‘goodbye’ and terminates. What I’m having trouble with is getting the program to accept input after the two possible points of input (is a palindrome, is not), and to then use the new input in the loops, and print the appropriate line each time.

Here’s what the output is supposed to look like:

Enter a string: rotor

rotor is a palindrome.

Enter a string: mummy

mummy is not a palindrome.

Enter a string:

Empty line read. Goodbye.

This is what I have so far, and it tests each input and returns the correct statement, but it does nothing when the input is empty:

System.out.print("Enter a string: ");
String input = in.next();
if (input.length() > 0) {
     int x = 0;
     int y = input.length()-1;
     while (x < y) {
          if (input.charAt(x) == input.charAt(y)) {
               x++;
               y--;
          }
          else {
               System.out.println(input + " is NOT a palindrome.");
               System.out.println("Enter a string: ");
               input = in.next();
          }
          System.out.println(input + " is a palindrome.");
          System.out.println("Enter a string: ");
          input = in.next();
     }
}
else {
     System.out.print("Empty line read - Goodbye!");
}

Any thoughts? This is homework, btw, so I’m not looking for The Answer so much as clues, or what I need to be looking at.

  • 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-12T04:29:39+00:00Added an answer on June 12, 2026 at 4:29 am

    OK, Since it’s your homework, I’ll just give you a brief description about how you can proceed: –

    • Since you need to continously take user input, so probably you would be needing some kind of loop, that can continue until a condition is reached (You can think, what loop constrct will go here)

    • Secondly, you need to ask user when he want to quit, so you need to specify a exit condition..

    • Third, for checking for palindrome, you need to check a string with it’s reverse..

    • Since you have to use nested loop, you can use length of the string entered, in your loop condition.. Remember, you just need to loop till half the length. Why, you need to find out.. then, compare first character with last, then 2nd character with 2nd last.. until characters are matching.. You need to find out when you will exit the loop..

    I think this much information will get you started..

    Also one more thing.. May be you are restricted with the use of any method, but it is absolutely bad idea and ugly design to do everything in main().. In fact any of your method should not do more than one task.. And especially your main() method should ideally be just 4 – 5 lines long..

    When coding a method, if you think this part is something different, move it outside to another method, and invoke it.. This is the way you should code..

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

Sidebar

Related Questions

I need to write a program that gets three numbers from the user, then
I need to write a simple program that records all the input from parallel
I need to write a haskell program that retrieves a file from command line
I need to write a little program in C that parses a string. I
I have a program that looks like this. I need to consistently write something
I write a program that gets as an input any string that contain the
I need to write a program that displays this information: netstat TCP / UDP
I need to write a program that prints 0.(03) for input 1 and 33.
I need to write a program that takes input line at a time and
I need to write a program that uses matrix multiplication to rotate an image

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.