palindrome, if the user inputs "what" the output is "thaw"

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Dullme
    New Member
    • Feb 2007
    • 3

    palindrome, if the user inputs "what" the output is "thaw"

    i can hardly know what is the code for this. I have researched palindromes, but unfortunately, I only have read about integers not for characters..I need some help..
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by Dullme
    i can hardly know what is the code for this. I have researched palindromes, but unfortunately, I only have read about integers not for characters..I need some help..
    There are many ways of doing this.
    Surely you must have an idea of your own on how to do it? Let's start with the more difficult one. If you were told to this this by making use of a char array, how would you do it?

    Comment

    • abctech
      New Member
      • Dec 2006
      • 157

      #3
      Originally posted by Dullme
      i can hardly know what is the code for this. I have researched palindromes, but unfortunately, I only have read about integers not for characters..I need some help..
      Are you trying to write a code to reverse a string or to check if a given word is a palindrome?

      As far as I know a palindrome is a word, phrase, verse, or sentence that reads the same backward or forward.
      Eg: Dad, Madam, "fall leaves after leaves fall" etc

      Comment

      • hirak1984
        Contributor
        • Jan 2007
        • 316

        #4
        well I am not sure if this can be called a plaindrome
        "fall leaves after leaves fall"
        I am putting some more examples...
        Don't nod
        Dogma: I am God
        Never odd or even
        Too bad – I hid a boot
        Rats live on no evil star
        No trace; not one carton
        Was it Eliot's toilet I saw?
        Murder for a jar of red rum
        May a moody baby doom a yam?
        Go hang a salami; I'm a lasagna hog!
        Satan, oscillate my metallic sonatas!
        A Toyota! Race fast... safe car: a Toyota
        Straw? No, too stupid a fad; I put soot on warts
        Are we not drawn onward, we few, drawn onward to new era?
        Doc Note: I dissent. A fast never prevents a fatness. I diet on cod
        No, it never propagates if I set a gap or prevention
        Anne, I vote more cars race Rome to Vienna
        Sums are not set as a test on Erasmus
        Kay, a red nude, peeped under a yak
        Some men interpret nine memos
        Campus Motto: Bottoms up, Mac
        Go deliver a dare, vile dog!
        Madam, in Eden I'm Adam
        Oozy rat in a sanitary zoo
        Ah, Satan sees Natasha
        Lisa Bonet ate no basil
        Do geese see God?
        God saw I was dog
        Dennis sinned
        Originally posted by abctech
        Are you trying to write a code to reverse a string or to check if a given word is a palindrome?

        As far as I know a palindrome is a word, phrase, verse, or sentence that reads the same backward or forward.
        Eg: Dad, Madam, "fall leaves after leaves fall" etc

        Comment

        • abctech
          New Member
          • Dec 2006
          • 157

          #5
          Originally posted by hirak1984
          "fall leaves after leaves fall"
          well I am not sure if this can be called a plaindrome
          Word palindromes are sentences that are read in either direction word by word.
          Eg:
          First ladies rule the state, and state the rule,"Ladies First."
          Fall leaves after leaves fall.

          Ref:-
          You can find the above examples under 'Symmetry by words' in http://en.wikipedia.org/wiki/Palindrome

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #6
            Alright then. I'll copy this to the cafe forum.

            Comment

            • Dullme
              New Member
              • Feb 2007
              • 3

              #7
              Code:
              import java.io.*;
                public class Pal
               {
                  public static void main (String args[])throws Exception
                {
                  String character;
                  //char word;
               	char[] temp; 
               	temp = new char[15];
               	char i;
              
                      System.out.println("Input word:");
              		for (i=0;i<14;i--) 
                   	{
              	  	    InputStreamReader word= new InputStreamReader(System.in);
                    		BufferedReader word2=new BufferedReader(word);
                    		character=word2.readLine();
                    		//character=String.parseInt(character);
                    		//temp[i]=character;
                   	}
                       	 //System.out.println ("Palindrome: ");
                         	 for (i=0;i<14;--i)
                       	{
                  	  	 System.out.print ("Palindrome: "+temp[i]);	
                  	  	}              
                }
               }
              That is my code.My problem is that, how can I make the user's word input to its opposite word? Example: He inputs MILK.. The output shoud be KLIM.
              Please help!

              Comment

              • r035198x
                MVP
                • Sep 2006
                • 13225

                #8
                Originally posted by Dullme
                Code:
                import java.io.*;
                public class Pal
                {
                public static void main (String args[])throws Exception
                {
                String character;
                //char word;
                	char[] temp; 
                	temp = new char[15];
                	char i;
                 
                System.out.println("Input word:");
                		for (i=0;i<14;i--) 
                	{
                		  InputStreamReader word= new InputStreamReader(System.in);
                		BufferedReader word2=new BufferedReader(word);
                		character=word2.readLine();
                		//character=String.parseInt(character);
                		//temp[i]=character;
                	}
                	 //System.out.println ("Palindrome: ");
                	 for (i=0;i<14;--i)
                	{
                		  System.out.print ("Palindrome: "+temp[i]);	
                		 } 
                }
                }
                That is my code.My problem is that, how can I make the user's word input to its opposite word? Example: He inputs MILK.. The output shoud be KLIM.
                Please help!
                Get the word as a string with the readline method. No need for a for loop for that.
                Then get its length using the string.length() method. After that you can now form a string by adding characters from the last to the first using a for loop.

                Comment

                • teku2024
                  New Member
                  • Mar 2007
                  • 1

                  #9
                  example codes of palindrome in NetBeans with interface

                  Comment

                  • r035198x
                    MVP
                    • Sep 2006
                    • 13225

                    #10
                    Originally posted by teku2024
                    example codes of palindrome in NetBeans with interface
                    Write them yourself like the OP is trying to do here. You will learn better that way.

                    Comment

                    Working...