Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit aa7347a

Browse files
committed
Add palindrome checker implementation
1 parent 7fb72fe commit aa7347a

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

‎Basic/Digits/palindrome.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
import java.util.Scanner;
3+
4+
public class palindrome {
5+
public static void main(String[] args) {
6+
Scanner sc = new Scanner(System.in);
7+
System.out.println("Enter the number: ");
8+
int num = sc.nextInt();
9+
10+
int result = isPalindrome(num);
11+
if (result == num) {
12+
System.out.println("The number is a palindrome: " + num);
13+
} else {
14+
System.out.println("The number is not a palindrome: " + num);
15+
}
16+
17+
18+
}
19+
20+
static int isPalindrome(int n) {
21+
int reverse = 0;
22+
while (n != 0) {
23+
int digits = n % 10;
24+
reverse = reverse * 10 + digits;
25+
n = n/10;
26+
27+
}
28+
return reverse;
29+
}
30+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /