0% found this document useful (0 votes)
3 views3 pages

Java Palindrome Checker Implementation

This Java program defines a Palindrom class to check if a string is a palindrome. The Palindrom class contains methods to set and get the string, as well as a helper method to check if the string is a palindrome by comparing the first and last characters and incrementally moving inward. The main method prompts the user for input, creates a Palindrom object, calls the helper method on the input, and prints whether it is a palindrome.

Uploaded by

lhei_cadatal2610
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views3 pages

Java Palindrome Checker Implementation

This Java program defines a Palindrom class to check if a string is a palindrome. The Palindrom class contains methods to set and get the string, as well as a helper method to check if the string is a palindrome by comparing the first and last characters and incrementally moving inward. The main method prompts the user for input, creates a Palindrom object, calls the helper method on the input, and prints whether it is a palindrome.

Uploaded by

lhei_cadatal2610
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

import [Link].

BufferedReader;
import [Link];
import [Link];

public class Palindrom {


String pal;
// constructor

public Palindrom(){
[Link]="";
}

public Palindrom(String str){


[Link]=str;
}

public boolean helper(){


int len=[Link]();
for(int i =0;i<(len % 2);i++ ){
if ([Link](i)!=[Link](len-i-1)){
return false;
}
}

return true;
}

public void setter(String pal) {


[Link] = pal;
}

public String getter() {


return pal;
}

// MAIN METHOD
public static void main(String[] args) throws IOException{
//instantiate Plaindrom object
Palindrom palObj=new Palindrom();
try {
BufferedReader in = new BufferedReader(new InputStreamReader([Link]));
String str = "";
do {
[Link]("Enter some word(Press '/' for end): ");
str = [Link]();
if (0==[Link]("/")){
break;
}else
{
[Link](str);
if ([Link]()){
[Link]("\n"+[Link]()+" is Plaindrom!");
}
else{
[Link]("\n"+[Link]()+" is not Plaindrom!");
}
}
}while (true);

} catch (IOException e) {
[Link]();
}

}//main

1. import [Link].*;
2. import [Link].*;
3. /**
4.   *
5.   * @author Developer
6.   */
7. public class Palindrome
8. {
9.  
10. public static void main(String[] args)throws IOException
11. {
12. Console console=[Link]();
13. String word=[Link]("Enter a word of yr choice");
14. int flag=1;
15. int left=0;
16. int right=[Link]()-1;
17. while(left<right)
18. {
19. if([Link](left)!=[Link](right))
20. {
21. flag=0;
22. }
23. left++;
24. right--;
25. if(flag==1)
26. {
27. [Link]("The word" + word + "is a palindrome");
28. }
29. else
30. {
31. [Link]("The word"+ word + "is not a palindrome");
32. }
33.  
34. }
35.  
36. }
37. }
{
flag=0;
}
left++;

You might also like