Skip to content

Commit 20c76c9

Browse files
committed
feat: Check if a number is a palindrome using reverse logic
🧠 Logic: - Read a number from user input. - Reverse the number by extracting and rebuilding digits. - Compare the reversed number with the original. - If both are equal, it's a palindrome (reads the same forward and backward). Signed-off-by: Somesh diwan <[email protected]>
1 parent 7f27c27 commit 20c76c9

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

Section8LoopAB/src/PalindromeANumber.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
1-
//Palindrome number means, a reverse of a
2-
//number is a number then it is called as a palindrome number.
1+
//Palindrome number means, a reverse of a number is a number then it is called as a palindrome number.
32

43
import java.util.Scanner;
5-
public class PalindromeANumber
6-
{
7-
public static void main(String[] args)
8-
{
4+
public class PalindromeANumber {
5+
public static void main(String[] args) {
96
Scanner sc = new Scanner(System.in);
107
System.out.println("Enter a Number: ");
118

129
int n = sc.nextInt();
1310

1411
int m = n; //Hold A Number into another Variable.
12+
1513
int rev =0, r;
16-
while (n>0)
17-
{
14+
15+
while (n>0) {
1816
r=n%10;
1917
rev=rev*10+r;
2018
n/=10;

0 commit comments

Comments
 (0)