Skip to content

Update Palindrome_or_not.java #76

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 23 additions & 15 deletions Palindrome_or_not.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<st.length();i++)
w=st.charAt(i)+w; //Reversing the String and Storing it.
if(st.compareTo(w)==0) //Comparing the string to original string
System.out.prinltn("Number is Pallindrome");
else
System.out.println("Number is Not Pallindrome");
class PalindromeOrNot {

public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

System.out.print("Enter a number: ");
String input = scanner.next(); // Get input from user

// Use StringBuilder to reverse the string
String reversed = new StringBuilder(input).reverse().toString();

// Check if the input and the reversed string are equal
if (input.equals(reversed)) {
System.out.println("The number is a palindrome.");
} else {
System.out.println("The number is not a palindrome.");
}

scanner.close();
}
}