From 4f6b7f876ae49eee624cdda9ef32b59d330a7a1d Mon Sep 17 00:00:00 2001 From: aakankshasuvarna27 <124388156+aakankshasuvarna27@users.noreply.github.com> Date: Mon, 7 Oct 2024 20:35:56 +0530 Subject: [PATCH] Update Palindrome_or_not.java 1. Simplified the comparison 2. The logic uses a more efficient StringBuilder to reverse the string 3. Fixed typos such as Sting (in the main method) and System.out.prinltn 4. Closed the Scanner to prevent resource leaks 5. Used equals() instead of compareTo() since we are simply checking for equality --- Palindrome_or_not.java | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/Palindrome_or_not.java b/Palindrome_or_not.java index 5a7e9d5..25f8383 100644 --- a/Palindrome_or_not.java +++ b/Palindrome_or_not.java @@ -4,22 +4,30 @@ Write a program to check the given number is palindrome or not? Descritpion : A Palindrome number is a number that remains the same when its digits are reversed. Like 16461, for example: we take 121 and reverse it, after revers it is same as original number */ + +package javacodes; + import java.util.Scanner; -class Palindrome_or_not { - - public static void main(Sting args[]) - { - Scanner x = new Scanner(System.in); - - String st=x.next(); - String w=""; // Creating new string to apply algo on! - int i; - for(i=0;i