Home Answers Viewqa Java-Beginners complete the code (palindrome)

 
 


Soso
complete the code (palindrome)
1 Answer(s)      4 years and 7 months ago
Posted in : Java Beginners

View Answers

December 10, 2008 at 11:29 PM


here is the standard code with full of description,so go according that u will sure find solution,if string will palimdrome that it will give true or false

public class Palindrome {
private String pal;

public Palindrome(String initPal) {
pal = initPal.toUpperCase();
}

public boolean isPalindrome() {

if (pal.length() <= 1) {
// String has only one character so it
// is a Palindrome by definition.
return true; // BASE CASE.
}

// Get the first and last characters of the String.
char first = pal.charAt(0);
char last = pal.charAt(pal.length()-1);

if (Character.isLetter(first) &&
Character.isLetter(last)) {
// The first and last characters are both letters..

if (first != last) {
// The first and last letters are different
// so the string is not a Palindrome.
return false; // BASE CASE.
}
else {
// The first and last characters are both letters,
// and they are both the same. So, the string is
// a palindrome if the substring created by dropping
// the first and last characters is a palindrome.
Palindrome sub = new Palindrome(
pal.substring(1,pal.length()-1));
return sub.isPalindrome(); // RECURSIVE CASE.
}
}
else if (!Character.isLetter(first)) {
// The first character in the string is not a letter.
// So the string is a palindrome if the substring created
// by dropping the first character is a palindrome.
Palindrome sub = new Palindrome(pal.substring(1));
return sub.isPalindrome(); // RECURSIVE CASE.
}
else {
// The last character in the string is not a letter.
// So the string is a palindrome if the substring created
// by dropping the last character is a palindrome.
Palindrome sub = new Palindrome(
pal.substring(0,pal.length()-1));
return sub.isPalindrome(); // RECURSIVE CASE.
}
}

public static void main(String[] args) {
Palindrome p1 = new Palindrome("Madam, I'm Adam.");
System.out.println(p1.isPalindrome());
Palindrome p2 = new Palindrome("Nope!");
System.out.println(p2.isPalindrome());
Palindrome p3 = new Palindrome("dad");
System.out.println(p3.isPalindrome());
Palindrome p4 = new Palindrome("Go hang a salami, I'm a lasagna hog.");
System.out.println(p4.isPalindrome());
}
}









Related Pages:
complete the code (palindrome) - Java Beginners
complete the code (palindrome)  Write a program that checks if a word is palindrome. A word is said to be palindrome if it reads the same forward.... complete the below code (step 3 and step 4 are not solved). import
palindrome
palindrome  program to find the given string is palindrome or not   Hi Friend, Try the following code: import java.util.*; public class...]; } if(st.equalsIgnoreCase(reversedSt)){ System.out.println("String is palindrome
PALINDROME
PALINDROME  how to find palindrome of a number WITHOUT using a string ??   Hi Friend, Try the following code: import java.util.... == reversedNumber){ System.out.print("Number is palindrome!"); } else
No complete code for AbstractWizardFormCOntroller Example
No complete code for AbstractWizardFormCOntroller Example  No complete codes
Palindrome
Palindrome  program to verify palindrome
palindrome - Java Beginners
is palindrome. A word is said to be palindrome if it reads the same forward... noon is a palindrome. Enter a word: moon moon is not a palindrome.  Hi friend, Code to solve the problem : import java.io.*; public class
palindrome
palindrome  write a program to print palindrome numbers between 500 to 700
palindrome - Java Beginners
palindrome  Write a program to find whether a given string is a palindrome or not  Hi Friend, Try the following code: import java.util.*; public class CheckPalindrome{ public static void main(String[] args
palindrome array problem
palindrome array problem  I'm having trouble figuring this assignment out. Can someone please help me? Generate (write the code) and save in an array Palidrome[250][5] all the 5 letter words using {a, b, c} Write the code
palindrome
palindrome  how to write in string of palindrome?   import... is palindrome"); } else{ System.out.println("String is not palindrome
palindrome
palindrome  how to write in string of palindrome   import... is palindrome"); } else{ System.out.println("String is not palindrome
To find palindrome no in a file - Java Beginners
To find palindrome no in a file  hi all i am having a problem...I wanted to write one java program where i have to count the no of palindrome...;Hi Prashant, Use the following code: import java.util.Scanner; import
Palindrome Number Example in Java
Palindrome Number Example in Java    ... the palindrome number and how to determine any number is palindrome or not. First of all we are going to read about the palindrome number.  This is the number
Check whether the number is palindrome or not
Check whether the number is palindrome or not A palindrome is a word, phrase... is palindrome or not. You can check it in various ways but the simplest method... if the reversed number is equal to the original. Here is the code: import java.util.
The Array Palindrome Number in Java
The Array Palindrome Number in Java       This is a Java simple palindrome number program. In this section you will read how to uses palindrome one dimensional array
No complete code for BeanNameUrlHandlerMapping With Command Class Example
No complete code for BeanNameUrlHandlerMapping With Command Class Example  There is no complete dispatcher-servlet.xml and we couldn't download the codes
complete this code (insertion sort) - Java Beginners
complete this code (insertion sort)  Your task is to develop part... inserted at last position of new list. complete step 4 in the uncompleted method... [unsorted.length]; /* * * complete this method
Check whether the sum of alternate digit of a number is palindrome or not.
Check whether the sum of alternate digit of a number is palindrome... by the user is palindrome or not. So, firstly we have to find the sum... of this number be 2+4+6 i.e 12) and then check whether this sum is palindrome
java palindrome
java palindrome  sir i need java program to print 1)integer palindrome 2)string palindrome
auto complete text box - Ajax
auto complete text box  How to create auto complete text box in jsp using ajax technology ? plz giv me steps wise code
Find Numbers which are palindrome and prime
Find Numbers which are palindrome and prime In this section, you will learn how to find the numbers from 1 to 500 which are palindrome and prime. To compute...() of boolean type. Now the list contains all the numbers which are palindrome
Request for complete code of the Spring 2.5 MVC User Registration Example
Request for complete code of the Spring 2.5 MVC User Registration Example ... to understand the Spring WebMVC flow but it is not complete. Can you please send me the complete code of this example or rest of the part. Best Regards, Uttam kumar
prime palindrome
prime palindrome  Hi I want to write a program in pascal that ask a user to input a number, the program then list all the prime number that are palindrome below the number entered. thks
prime palindrome
prime palindrome  Hi I want to write a program that ask a user to input a number, the program then list all the prime numbers that are palindrome below the number entered. In pascal language Thanks
Complete Hibernate 4.0 Tutorial
Complete Hibernate 4.0 Tutorial Hibernate is a Object-relational mapping (ORM... and implementation classes, deprecated functions, classes clean up. Given below the complete... hibernate by example hibernate repository hibernate sample code
need complete jsp code for transactions using mysql - WebSevices
need complete jsp code for transactions using mysql  iam doing online banking project.i want the code to transfer funds from one account to another... to lasya or lasya to prathika. I need complete jsp code for transactions using
Ajax Auto Complete Tutorial
Auto Complete Example The auto complete feature helps the user to input... complete with JQuery is given below, to run this example you need to import two... it will display message as shown below: Download Select Source Code
Complete JDBC Tutorial
Complete JDBC ( Java Database Connectivity ) Tutorial In this complete JDBC.... This is the complete tutorial on JDBC at one place. Select the topics you want to learn and see the related example code. JDBC ( Java Database connectivity
Auto Complete Text Box - JSP-Servlet
Auto Complete Text Box  Please help me in Aotocomplete text box code. I m a java programmer. I m working on jsp tech. please give me the code for Autocomplete text box in which the values will generate from database table
Auto Complete Text Box - JSP-Servlet
Auto Complete Text Box - JSP-Servlet  Auto Complete Text Box Please help me in Aotocomplete text box code. I m a java programmer. I m working on jsp tech. please give me the code for Autocomplete text box in which the values
palindrome - Java Beginners
palindrome  example of java program if it is a palindrome or not palindrome   Hi friend, Example to check the number is a palindrome...){ System.out.print("Number is palindrome!"); } else
palindrome - Java Beginners
palindrome  determines whether or not it is a palindrome. if the number is not five... == digit4)){ System.out.print("Number is palindrome!"); } else{ System.out.println("Number is not palindrome!"); } } catch(Exception e  
palindrome - Java Beginners
palindrome in java code  I need an example of palindrome in Java ...;& (digit2 == digit4)){ System.out.print("Number is palindrome!"); } else{ System.out.println("Number is not palindrome!"
Java: Example - Palindrome test
Java: Example - Palindrome test //========================================================= isPalindrome // This method returns 'true' if the parameter // is a palindrome, a word that is spelled the // same both
jQuery auto complete through database using JSP
jQuery auto complete through database using JSP In this tutorial, we will implement auto complete through database using JSP. In this example a text box is given, when you enter name of any Indian state , it will auto complete
Exercise - Palindrome
Java: Exercise - Palindrome Problem Write a method which returns true if the string parameter is a palindrome. A palindrome is any "word" which... return false if the argument is not a palindrome. Signature
write a program in java to demonstrate the complete life cycle of servlet:
write a program in java to demonstrate the complete life cycle of servlet:  l have an assignment question. i don't know how to write the code for this program. my question is :Write a program in Java to demonstrate the complete
palindrome - Java Beginners
palindrome  import java.io.*; class Palindrome { System.out.println("Enter a word:"); BufferedReader br=new BufferedReader(new InputReaderStream(System.in)); String word; word=br.readLine(); public static void main
Auto complete text box using jQuery plug in
Auto complete text box using jQuery  plug in In this tutorial, we will discuss about how to implement auto complete using jQuery plug...; in text box : Download Source Code Click here to see demo
Finding all palindrome prime numbers - Java Beginners
Finding all palindrome prime numbers  How do i write a program to Find all palindrome prime numbers between two integers supplied as input (start and end points are excluded
Kilometers to Miles - Complete
Java NotesExample - Kilometers to Miles - Complete Here is the entire working program. The code that adds and defines a button listener is at Note 1..., but it's a good idea to get used to separating the user interface code from the "model
Palindrome program in Java
Palindrome program in Java helps programmers to determine if a number or string is palindrome or not. palindrome number or string remains unchanged when.... The logic used in Java program behind finding a number or sting is palindrome
The Complete Spring Tutorial
The Complete Spring Tutorial In this tutorial I...; UrlBasedViewResolver Example The UrlBasedViewResolver example with free code.  ... the code from here
Complete Hibernate 3.0 Tutorial
Complete Hibernate 3.0 Tutorial     ... solution for Java. Download Source Code Example of tutorial Introduction... class and add necessary code in the contact.hbm.xml file.  
Program to display palindrome numbers between some range
Program to display palindrome numbers between some range  Hi!I want a java program to display palindrome numbers between 100 to 1000.can you please explain me the logic with an example   import java.util.*; public
complete coding for shopping card
complete coding for shopping card  complete coding for shopping card   Please visit the following link: Shopping Cart Application
Complete example of JQuery with JAX
Complete example of JQuery with JAX  Hi, I completed the basic J Query tutorial. But my project requirement is to use the JQuery with Ajax. Could you please provide me complete example of Jquery with Ajax integration. Thanks
CAPXOUS.AutoComplete
CAPXOUS.AutoComplete       A handy AJAX auto complete component. Developers could build features like area code auto complete, group code auto complete, material code auto complete, etc
CAPXOUS.AutoComplete
; CAPXOUS.AutoComplete is G???? A handy AJAX auto complete component. Developers could build features like area code auto complete, group code auto complete, material code auto complete, etc. with ease! Read full Description
Complete php tutorial
Complete php tutorial  Hi, I am trying to find the url to learn complete PHP in easily. Can some one provide me url for complete php tutorials. Thanks   Hi, Learning PHP is now very easy from tutorials from many