IN JAVA PROGRAMMING LANGUAGE The concept of a 5-digit palindrome number is a 5-d
ID: 3752125 • Letter: I
Question
IN JAVA PROGRAMMING LANGUAGE The concept of a 5-digit palindrome number is a 5-digit number that reads the same from left to right and from right to left. For example, 12121, 45454, and 14741 are valid 5-digit palindrome numbers. Design (pseudocode) and implement (source code) a program (name it FiveDigitPalindrom) that reads a 5-digit number from the user (as integer value, not string) and then mathematically (using division and remainder operations) determines whether the entered number is a 5-digit palindrome or not. Assume valid inputs are from 11111 to 9999. The program rejects any input outside that range with the message “Invalid 5-digit number. Try again”. Document your code and properly label the input prompts and the outputs as shown below. Sample run 1: Entered number: 6754 Judgment: Invalid 5-digit number. Try again Sample run 2: Entered number: 12321 Judgment: Valid 5-digit palindrome Sample run 3: Entered number: 12324 Judgment: Invalid 5-digit palindrome
Explanation / Answer
/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int ans = 0, x=1;
while(ans!=-1){
System.out.println("Sample run "+x++);
System.out.print("Enter a 5 digit number(Enter -1 to exit): ");
ans = sc.nextInt();
if(ans<10000 || ans>99999){
System.out.println("Invalid 5 digit number");
}else{
if(ans%10 == ans/10000 && ((ans%100)/10)==(ans%10000)/1000 ){
System.out.println("Valid 5 digit palindrome");
}else{
System.out.println("Invalid 5 digit palindrome");
}
}
}
}
}
This is the ideone link for proper indentation: https://ideone.com/fDDCKx