upd
This commit is contained in:
16
9. Palindrome Number/Solution.java
Normal file
16
9. Palindrome Number/Solution.java
Normal file
@@ -0,0 +1,16 @@
|
||||
class Solution {
|
||||
public static void main(String[] args) {
|
||||
int test[] = {121, -121, 10};
|
||||
|
||||
for (int t : test) {
|
||||
System.out.println("isPalindrome(" + t + ") = " + isPalindrome(t));
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isPalindrome(int x) {
|
||||
StringBuilder sb = new StringBuilder(Integer.toString(x));
|
||||
sb.reverse();
|
||||
String reversed = sb.toString();
|
||||
return Integer.toString(x).equals(reversed);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user