We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,374 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

How to do the main

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...

4
Contributors
9
Replies
1 Day
Discussion Span
1 Year Ago
Last Updated
10
Views
sarrrry92
Newbie Poster
5 posts since Apr 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

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?

NormR1
Posting Sage
Team Colleague
7,742 posts since Jun 2010
Reputation Points: 1,158
Solved Threads: 793
Skill Endorsements: 16

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

sarrrry92
Newbie Poster
5 posts since Apr 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

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

sarrrry92
Newbie Poster
5 posts since Apr 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

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?

NormR1
Posting Sage
Team Colleague
7,742 posts since Jun 2010
Reputation Points: 1,158
Solved Threads: 793
Skill Endorsements: 16

all of them

sarrrry92
Newbie Poster
5 posts since Apr 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

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

NormR1
Posting Sage
Team Colleague
7,742 posts since Jun 2010
Reputation Points: 1,158
Solved Threads: 793
Skill Endorsements: 16

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

LolaLove
Newbie Poster
1 post since Apr 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

Cross posted at Click Here

NormR1
Posting Sage
Team Colleague
7,742 posts since Jun 2010
Reputation Points: 1,158
Solved Threads: 793
Skill Endorsements: 16

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.

joankim
Junior Poster in Training
59 posts since Dec 2011
Reputation Points: 10
Solved Threads: 2
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0878 seconds using 2.8MB