Question
Question: In JAVA, also why is my answer wrong, thanks! 3-12) (Palindrome number) Write a program that prompts the user to enter a three-digit integer
Question: In JAVA, also why is my answer wrong, thanks!
3-12) (Palindrome number) Write a program that prompts the user to enter a three-digit integer and determines whether it is a palindrome number. A number is a palindrome if it reads the same from right to left and fro:rm left to right. SAMPLE RUN #4: java Palindrome Hide Invisibles Highlight: Show Highlighted Only Enterathree-digitinteger:363 363isapalindrome
wrong answer:
import java.util.Scanner;
public class Palindrome{ public static void main(String[] args){
Scanner in = new Scanner(System.in);
System.out.print("Enter a three-digit integer:"); int user_input = in.nextInt();
int temp_remaning = 0;
int d1 = user_input % 10; temp_remaning = user_input / 10; int d2 = temp_remaning % 10; int d3 = temp_remaning / 10;
String rev = Integer.toString(d3) + Integer.toString(d2) + Integer.toString(d1); String original = Integer.toString(user_input);
if(rev.equals(original)){ System.out.println(original + " is a palindrome"); } else{ System.out.println(original + " is not a palindrome"); } } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started