Advertisement
MaximTakkaTo

Untitled

Sep 22nd, 2021
898
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.54 KB | None | 0 0
  1. public class ApplicationRunner {
  2.     public static String CHECKING_SENTENCE = "topot";
  3.  
  4.     public static void main(String[] args) {
  5.         System.out.println(isPalindrome(CHECKING_SENTENCE));
  6.     }
  7.  
  8.     public static boolean isPalindrome(String sentence) {
  9.         boolean isValid = true;
  10.         int sentenceLength = sentence.length();
  11.         for (int i = 0; i < sentenceLength / 2 && isValid; ++i) {
  12.             isValid = sentence.charAt(i) == sentence.charAt(sentenceLength - i - 1);
  13.         }
  14.         return isValid;
  15.     }
  16. }
  17.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement