Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: How to do the main ?

  1. #1
    Junior Member
    Join Date
    Apr 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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)
    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

    public class Palindrome
    {
      public static void main(String [] args) {
         String[] s = new String[5];
     
        }
        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;
            else
                return false;
            }
    }


    thanks...


  2. #2
    Member
    Join Date
    Jan 2012
    Location
    Hellas
    Posts
    284
    Thanks
    11
    Thanked 59 Times in 57 Posts

    Default Re: How to do the main ?

    Hello sarrrry92!
    You are initializing your array but the values it keeps are the default ones (null). You should better fill it with some Strings, some of them palindromes
    For example:
    String[] s = {"anna", " dien", "omnnmo"};
    Then you can loop through your array and call the pallindromCheck(String n) method.
    And something else i noticed:
    if (x==n)
    You should use the String's equals() method instead of the == operator when comparing Strings.
    Hope it helps.

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: How to do the main ?

    Cross posted at How to do the main | DaniWeb
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Exception at main...
    By Paetilium in forum What's Wrong With My Code?
    Replies: 4
    Last Post: March 15th, 2012, 06:37 PM
  2. [SOLVED] main error
    By Shivam24 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: August 29th, 2011, 08:28 PM
  3. Need Help with main arg for the project
    By Nightmare in forum Collections and Generics
    Replies: 4
    Last Post: November 30th, 2010, 02:40 PM
  4. Replies: 6
    Last Post: November 12th, 2010, 04:40 AM
  5. Replies: 2
    Last Post: March 26th, 2010, 11:22 AM