Advertisement
sudoaptinstallname

Untitled

Jan 29th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. package com.company;
  2.  
  3. /*
  4. Amon Guinan
  5. January 2019
  6. Checks whether input string is a palindrome.
  7. */
  8. import java.util.*;
  9.  
  10. class Six_sixtySeven
  11. {
  12. public static void main(String args[])
  13. {
  14. Scanner scanner = new Scanner(System.in);
  15.  
  16. System.out.println("Enter a palindrome:");
  17. String input = scanner.nextLine();
  18. String opposite = "";
  19. int size = input.length();
  20.  
  21. for (int x = size - 1; x >= 0; x--)
  22. opposite += input.charAt(x);//Really good algorithm for reading incrementally!
  23.  
  24. if (input.equals(opposite))
  25. System.out.println("Valid palindrome");
  26. else
  27. {
  28. System.out.println("Not a valid palindrome");
  29. }
  30.  
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement