Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Ex4 {
- public static void main(String[] args) {
- String word = "kayak";
- char[] palindrome = new char[word.length()];
- for (int i = 0; i < word.length(); i++) {
- palindrome[i] = word.charAt(i);
- }
- int isPalindrome = 0; //true - 0, false - 1
- int sumPalindrome = 0;
- for (int i = 0; i < word.length(); i++) {
- if (palindrome[i] == palindrome[word.length() - 1 - i]) {
- isPalindrome = 0;
- } else {
- isPalindrome = 1;
- }
- sumPalindrome += isPalindrome;
- }
- if (sumPalindrome == 0 && word.length() > 0) {
- System.out.println("Palindrome.");
- } else {
- System.out.println("Not a palindrome.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement