Showing posts with label palindrome number. Show all posts
Showing posts with label palindrome number. Show all posts

Write a Java program to input a number and check if it is palindrome or not

 Write a program  in Java to input a number and check if it is  palindrome or not

Palindrome : palindrome is a word, number, phrase, or other sequence of characters which reads the same backward as forward, such as madam or racecar.

import java.util.Scanner;

public class Palin {
public static void main(String[] args) {
Scanner sc =new Scanner(System.in);
System.out.print("Enter A Number : ");
int num =sc.nextInt();
int rev=0,ldigit;
int temp=num;
while (temp!=0) {
ldigit=temp%10;
rev=rev*10+ldigit;
temp=temp/10;
}
if (num==rev) {
System.out.println(num +" is Palindrome");
} else {
System.out.println(num +" is not Palindrome");
}
}
}


 

OUTPUT

1. 
     Enter a Number : 123454321
     123454321 is Palindrome

2. 
     Enter a Number : 345232
     345232 is not Palindrome



Share:

Write a program in c++ to input a number and check if it is palindrome or not

   

Write a program  in c++ to input a number and check if it is  palindrome or not

Palindrome : palindrome is a word, number, phrase, or other sequence of characters which reads the same backward as forward, such as madam or racecar.

#include <iostream>
using namespace std;
int main()
{
    int nnumldigitrev = 0;
    cout << "Enter a Number : ";
    cin >> n;
    num = n;
    while (num != 0)
    {
        ldigit = num % 10;
        rev = rev * 10 + ldigit;
        num /= 10;
    }
    if (rev == n)
    {
        cout << n << " is palindrome";
    }
    else
        cout << n << " is not palindrome";
}

OUTPUT

1. 
     Enter a Number : 123454321
     123454321 is palindrome

2. 
     Enter a Number : 345232
     345232 is not palindrome



Share:

Pageviews