1,105,450 Community Members

How to do the main

sarrrry92
Newbie Poster
5 posts since Apr 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
Unverified Member
 
0
 

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

Member Avatar
NormR1
Posting Sage
7,723 posts since Jun 2010
Reputation Points: 563 [?]
Q&As Helped to Solve: 793 [?]
Skill Endorsements: 16 [?]
Team Colleague
 
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?

sarrrry92
Newbie Poster
5 posts since Apr 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
Unverified Member
 
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 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
Unverified Member
 
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

Member Avatar
NormR1
Posting Sage
7,723 posts since Jun 2010
Reputation Points: 563 [?]
Q&As Helped to Solve: 793 [?]
Skill Endorsements: 16 [?]
Team Colleague
 
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?

sarrrry92
Newbie Poster
5 posts since Apr 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
Unverified Member
 
0
 

all of them

Member Avatar
NormR1
Posting Sage
7,723 posts since Jun 2010
Reputation Points: 563 [?]
Q&As Helped to Solve: 793 [?]
Skill Endorsements: 16 [?]
Team Colleague
 
0
 

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

LolaLove
Newbie Poster
1 post since Apr 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
Unverified Member
 
0
 

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

Member Avatar
NormR1
Posting Sage
7,723 posts since Jun 2010
Reputation Points: 563 [?]
Q&As Helped to Solve: 793 [?]
Skill Endorsements: 16 [?]
Team Colleague
 
0
 

Cross posted at Click Here

Member Avatar
joankim
Junior Poster in Training
59 posts since Dec 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 2 [?]
Skill Endorsements: 0 [?]
 
0
 

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.

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article