Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Program 2: Palindrome Number ID: ID002 Make sure you include this ID as a System

ID: 3733184 • Letter: P

Question

Program 2: Palindrome Number

ID: ID002

Make sure you include this ID as a System.out.println() message at the beginning of your program. This helps us with grading, and is required.

Before beginning this project, make sure to completely read through the instructions, and then draw the flowchart. The flowcharts will be taken up at the beginning of our next Lab.

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 from left to right. For example, “373” is a palindrome number, but “519” is not.

The pseudocode is provided to you below:

This program will determine whether a number is a palindrome

num <- user input

firstDigit <- num / 100

num <- num % 10

(num now represents the last digit)

if firstDigit equals num, then

display “This was a palindrome”

else

display “This was not a palindrome”


Below is the input and the output we expect from your program. This is to help you know if you are on the right track.

Example input :

373

Example output:

ID002

Enter a palindrome: [integer]

This was a palindrome




Example input :

578

Example output:

ID002

Enter a palindrome: [integer]

This was not a palindrome

Explanation / Answer

ThreeDigitPalindrome.java

import java.util.Scanner;

public class ThreeDigitPalindrome {

public static void main(String[] args) {

System.out.println("ID002");

Scanner scan = new Scanner(System.in);

System.out.println("Enter a 3-digit number:");

int num = scan.nextInt();

int firstDigit = num/100;

num = num % 10;

if(firstDigit==num) {

System.out.println("This was a palindrome");

} else {

System.out.println("This was not a palindrome");

}

}

}

Output:

ID002
Enter a 3-digit number:
373
This was a palindrome

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote