In: Computer Science
(Palindrome number - A number is a palindrome if it reads the same from right to left and from left to right, for example 676 is a palindrome number) Write a program that prompts the user to enter a three-digit integer number and determines whether it is a palindrome number or not
In Java Please
/************ Palindrome.java *************/
import java.util.Scanner;
public class Palindrome {
public static void main(String[] args) {
int number;
/*
* Creating an Scanner class object
which is used to get the inputs
* entered by the user
*/
Scanner sc = new
Scanner(System.in);
while (true) {
// Getting the
input entered by the user
System.out.print("Enter a three difit number :");
number =
sc.nextInt();
if (number <
100 || number > 999) {
System.out
.println("** Invalid.Must be a three digit number **");
} else {
break;
}
}
boolean b =
isPalindrome(number);
if (b) {
System.out.println(number + " is a palindrome");
} else {
System.out.println(number + " is not a palindrome");
}
}
private static boolean isPalindrome(int number)
{
// Declaring variables
int temp = 0, val;
int reverse_number = 0;
val = number;
// This while loop will reverse the
number
while (number > 0) {
temp = number %
10;
reverse_number =
reverse_number * 10 + temp;
number = number
/ 10;
}
if (val == reverse_number)
return
true;
else
return
false;
}
}
/*******************************************************/
/*******************************************************/
Output:
/*******************************************************/