![]() Now we will compare the original and resultant strings. If the reversed string is the same as the original string then print “Palindrome” or else print “Not Palindrome”. After reversing it, convert back the StringBuilder object to a String object. The input is taken as a string and converted as a StringBuilder object so that we can call the reverse() method. We have defined a class Palindrome and created a Scanner object to get input from the user. StringBuilder sb = new StringBuilder(string) String Palindrome In Java Using Reverse Method import The syntax of reverse() method in StringBuilder class:- public StringBuilder reverse() In Java, StringBuilder and StringBuffer classes contain a pre-defined reverse() method to reverse the string type values. R a d a r -> r a d a R String Palindrome In Java Using reverse() Method ![]() Sign Language Word Search Puzzle Palindrome String Exampleīefore going to the coding let us see some examples of palindrome string:- radar, level, madam, civic, rotor, refer, and e.t.c. Observe these words they are the same when spelled backward also.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |