Computer Science, asked by AdvaitSemwal, 7 months ago

Input a three digit number from user and check whether it is a palindrome number or not.
A number is said to be palindrome if remains same after reversing. Do not make use of if-else.
Eg: 121, 545, 555 etc.

Answers

Answered by Oreki
1

import java.util.Scanner;

public class Palindrome {

static boolean isPalindrome(int number) {

String temp = new StringBuilder(number + "").reverse( ).toString( );

return Integer.parseInt(temp) = = number;

}

public static void main(String[ ] args) {

System.out.print("Enter a Three-Digit number - ");

int number = new Scanner(System.in).nextInt( );

System.out.printf("It is%sa Palindrome number", isPalindrome(number) ? " " : " not ");

}

}

Answered by anindyaadhikari13
2

Question:-

  • Write a program to input a number and check whether it is a palindrome number or not.

Code:-

class Palindrome

{

static void main(int n)

{

int n1=n, s=0;

for(;n!=0;n/=10)

s=s*10+n%10;

System.out.println((s==n)?"Palindrome.":"Not Palindrome.");

}

}

Similar questions