#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    1
    Rep Power
    0

    Array for Palindrome


    Hi, I was wondering if anyone could help me with this. We were given the following layout and have to fill in the rest to make the array program for palindromes to work but I just can't get it to!

    public class palindrome
    {
    public static void main(String[] args)
    {
    int i;
    int j;
    int palindromeSize=;//ENTER NUMBER OF LETTERS IN SUSPECTED PALINDROME
    char palindrome[]=new char[palindromeSize];//Create array to hold the characters of a palindrome to be tested

    //ENTER CHARACTERS OF PALINDROME INTO ARRAY
    for)
    }
    {


    palindrome[i]=inputCharacter;

    }
    System.out.print("The word or phrase to be tested is: ");
    //traverse the array to print out the suspected palindrome
    for()
    {

    ;
    }
    System.out.println();
    //A palindrom is tested by comparing first and last letter, second and second last letter etc until middle
    for()
    {
    if()
    {
    System.out.println("and it is not a palindrome! ");
    break;

    }
    if()//middle of word is reached
    {
    System.out.println("and it is a palindrome!");
    }
    }
    }
    }
  2. #2
  3. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    Hi,

    so what's your approach? What did you try? Where exactly did you have problems?

    Please note that this is not a homework service, so we won't give you a solution for you to copy and paste or something. We can help you with concrete questions, but you have to do the actual programming.
  4. #3
  5. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,724
    Rep Power
    348
    It'd help if you'd edit your post and wrap the code in code tags.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Location
    Tempe
    Posts
    38
    Rep Power
    3
    Palidromes arent that diffucult. Since its fill in the blank, it makes it easier..

    Now i do not know why you have an array for this activity. You could always just ask the user for a string, then give set that string to a string primitive..

    Code:
    System.out.println("Enter a string: ");
            String value = scan.nextLine();
    Then do a loop, which checks the string length and if the length is equal to one, then its a palindrome if not then simply have it loop through a comparison of the first letter with the last letter (best idea to use char and substring), then if it doesnt equal then break out of the loop and say its not a palindrome..

    Hopefully that made some sense.
  8. #5
  9. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    Originally Posted by cyimking
    Hopefully that made some sense.
    Great. You've basically repeated the code comments and the given layout.

    Bursting in with a "solution" when others have just asked the OP for his own thoughts is also not very nice.
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    7
    Rep Power
    0

    Array for Palindrome


    I think Array are use for define any big size ratio in easiest way. Palindrome array is advance of array function.

IMN logo majestic logo threadwatch logo seochat tools logo