0% found this document useful (0 votes)
25 views

Palindrome Number - Java

The code checks if an integer is a palindrome by converting it to a string, comparing the first and last characters, incrementing the first index and decrementing the last, and returning false if any characters do not match or true if the indices pass.
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

Palindrome Number - Java

The code checks if an integer is a palindrome by converting it to a string, comparing the first and last characters, incrementing the first index and decrementing the last, and returning false if any characters do not match or true if the indices pass.
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

class Solution {

public boolean isPalindrome(int x) {


if(x < 0)
return false;
else if(String.valueOf(x).length() == 1)
return true;

String str = String.valueOf(x);

int i = 0;
int j = str.length() -1;
while(j > i){
if(str.charAt(i) != str.charAt(j))
return false;
i++;
j--;
}
return true;
}
}

You might also like