Never mind my last post(I don't know how to detete)

How to do the main?
Write a program that has an array of 5 Strings, and determines which ones are
palindromes (letter-case does not matter) .
Your code will be written in one class Palindrome.java and has a main() method.
Please note the following:
1. Do not write all your code in the main(). The main should only initialize the array, and
print the palindrome words found. You can break your problem into smaller pieces
dealt with in separate methods. For example you might need a method that determines
whether a String is a palindrome or not (What would it take as a parameter? what
would it return?)

public class Palindrome
{
  public static void main(String [] args) {
     String[] s = new String[5];
     (how to write this)
    }
    public static String Reverse(String x) {
        String hold = "";
        char [] c = x.toCharArray();
        for (int i = c.length-1; i>0; i--)
        hold = hold +c[i];
        return hold;
    }
    public static boolean pallindromCheck(String n) {
        String x=Reverse(n);
        if (x==n)
            return true;
        el

se
                return false;
            }



}

thanks...

Recommended Answers

All 9 Replies

What does the main method have to do? Make a list of the steps it needs to do and then try writing the code to do those steps. Which step(s) are you having trouble with?

main method have to do? Make a list of the steps it needs
The main should only initialize the array, and
print the palindrome words found. You can break your problem into smaller pieces
dealt with in separate methods. For example you might need a method that determines
whether a String is a palindrome or not

main method have to do? Make a list of the steps it needs
The main should only initialize the array, and
print the palindrome words found. You can break your problem into smaller pieces
dealt with in separate methods. For example you might need a method that determines
whether a String is a palindrome or not

Which of the steps that the main is to do are you having problems. Work on them one at a time. What's the first one?

all of them

Pick one and do that first. When that is done move on to the next one.

i would be interested in knowing how to do it as well, have you figured it out yet?

Member Avatar for joankim

First of all, I find it annoying how you didnt put any effort at all into posting your question. I had a hard time figuring out why you asked about something, and then gave a bunch of instructions. I will help you out, but next time you really should do a better job on the original post.

First of all. On line 11, you are comparing strings. == does not work for strings. Rewrite that line.

Now for main().
You should call on your (misspelled) palindromeCheck() class. Assign the result to a boolean variable. Then make a if/else statement in main. If your variable is true, print that, or if it's not, print that. If you still are stuck, rewrite your original post and then answer under here with what exactly you need, and I will gladly help you more. Good luck.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.