forked from yesiamrajeev/Hacktoberfest2024
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Palindrome number checker in java yesiamrajeev#151
- Loading branch information
1 parent
36f6df6
commit 94de3ca
Showing
1 changed file
with
23 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |