Program to check palindrome or not in - JAVA - Java2021 : Online Tutorials Hub

Java2021 : Online Tutorials Hub

JAVA | Advance Java | MySQL | Data Structure | Git | HTML | CSS | JS

Latest

Post Top Ad

Program to check palindrome or not in - JAVA

Write a program to check  palindrome or not

package Programs;
public class Palindrome {
    public static void main(String[] args) {
        int number=122;
        int temp=number;
        int rev=0,rem;
        while (temp!=0){
            rem=temp%10;
            rev=rev*10+rem;
            temp=temp/10;
        }
        if (number==rev){
            System.out.println(number+ " is palindrome");
        }
        else {
            System.out.println(number+ " not palindrome");
        }
        }
    }
Output : 


Write a program using user input (Scanner class)
public class Palindrome
{
    public static void main(String[] args) 
    {
        int number;
        System.out.println("enter the number");
        Scanner scanner=new Scanner(System.in);
        number=scanner.nextInt();
        int temp=number;
        int rev=0,rem;
        while (temp!=0)
        {
        rem=temp%10;
        rev=rev*10+rem;
        temp=temp/10;
        }
        if (number==rev){
        System.out.println(number+ " is palindrome");
        }
        else {
        System.out.println(number+ " not palindrome");
        }
    }

}
Output :  






Click to next or Start with your Choice
-Important Programs for Freshers
Sorting and Searching Programs
Learn Pattern Programs 
Click to learn Array Programs
Click to Learn MySQL 
for any complaint regarding my Blog please visit contact us page and write what problem you have!

No comments:

Pages