Guest User

Untitled

a guest
Jun 24th, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class Palindrome{
  4. Scanner sc = new Scanner(System.in);
  5. String word;
  6. String Word;
  7. int size;
  8. int i;
  9. int left;
  10. int right;
  11. char charAt;
  12.  
  13.  
  14. void initialize(){
  15. System.out.println("Give a word of which you want to know wether it is a palindrome or not.");
  16. word = sc.next();
  17. size = word.length();
  18. System.out.print(word+" - ");
  19. }
  20. boolean recursive(String Word){
  21. word = Word
  22. return palindrome(word, 0);
  23. }
  24. boolean palindrome( int i){
  25. if (i == size){
  26. System.out.print("palindrome - ");
  27. return true;
  28. } else if (word.charAt(size - i) == word.charAt(i)) {
  29. return palindrome(word, ++i);
  30. } else {
  31. System.out.print("no palindrome - ");
  32. return false;
  33. }
  34. }
  35. boolean iterative(String Word){
  36. word = Word
  37. left = 0;
  38. right = size;
  39.  
  40. while(left < right){
  41. if (word.charAt(left) != word.charAt(right)){
  42. System.out.print("no palindrome");
  43. left++ ;
  44. right-- ;
  45. return false;
  46. }else{
  47. System.out.print("palindrome");
  48. return true;
  49. }
  50. }
  51. }
  52.  
  53. }
  54. void show(){
  55. initialize();
  56. boolean recursive();
  57. boolean iterative();
  58. }
  59. public static void main(String[] args) {
  60. new Palindrome().show();
  61.  
  62. }
Add Comment
Please, Sign In to add comment