Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package week11.solutions;
- import java.util.Scanner;
- public class PalindromeMethods {
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- System.out.print("Enter a string: ");
- String s = input.next();
- boolean result = isPalindrome(s);
- System.out.println(s + (result ? " is a palindrome" : " is not a palindrome"));
- }
- static boolean isPalindrome(String word) {
- int low = 0;
- int high = word.length() - 1;
- while (low < high) {
- if (word.charAt(low) != word.charAt(high)) {
- return false;
- }
- low++;
- high--;
- }
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement