Skip to content

Commit

Permalink
Added Palindrome number checker in java yesiamrajeev#151
Browse files Browse the repository at this point in the history
  • Loading branch information
judiemosinabre committed Oct 27, 2024
1 parent 36f6df6 commit 94de3ca
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions Java/PalindromeNumber.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import java.util.Scanner;

public class PalindromeNumber {

public static boolean isPalindrome(int x) {

int length = String.valueOf(x).length();
String num = String.valueOf(x);
for (int i = 0; i < length; i++) {
if (num.charAt(i) != num.charAt(length - 1 -i)){
return false;
}
}
return true;
}

public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.print("Input number: ");
int num = scan.nextInt();
System.out.println("Is it Palindrome?: " + isPalindrome(num));
}
}

0 comments on commit 94de3ca

Please sign in to comment.