Question

Write an application in java that reads in a five-digit integer and determines whether it is...

Write an application in java that reads in a five-digit integer and determines whether it is a palindrome. If the number is not five digits long, display an error message and allow the user to enter a new value. Tips: 1. Determine the number of digits in the value input by the user , i.e. prompt the user to enter the number of digits of the number. Use a while loop to determine whether the user input contains the proper number of digits. In the condition, determine whether digits is equal to 5. If not, input a new value from the user and determine whether the new value contains the proper number of digits. When the number of digits is five, the loop should terminate. 2. Use division and remainder operations to obtain separate digits. 3. For a 5-digit number to be a palindrome, the first and fifth digits must be the same and the second and fourth digits must be the same.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Java code for the above question:

import java.util.*;

class Main {

   public static void main(String[] args){

        Scanner s = new Scanner(System.in);

        int input, len, x;

        System.out.print("Enter a 5-digit integer\n");

        while(true){

            len=0;

            input=s.nextInt();

            x=input;

            while(x > 0){

                x=x/10;

                len++;

            }

            if(len!=5)

                System.out.print("Please enter a 5-digit integer\n");

            else if(len==5){

                int rnum = 0;

                x=input;

                while(x > 0) {

                    rnum=rnum*10+x%10;

                    x=x/10;

                }

                if(input==rnum)

                    System.out.print(input+" is a palindrome");

                else

                    System.out.print(input+" is not a palindrome");

                System.exit(0);

            }

        }

    }

}

Output:

Add a comment
Know the answer?
Add Answer to:
Write an application in java that reads in a five-digit integer and determines whether it is...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • JAVA: 4.31 (Palindromes) A palindrome is a sequence of characters that reads the same backward as...

    JAVA: 4.31 (Palindromes) A palindrome is a sequence of characters that reads the same backward as forward. For example, each of the following five-digit integers is a palindrome: 12321, 55555, 45554 and 11611. Write an application that reads in a five-digit integer and determines whether it’s a palindrome. If the number is not five digits long, display an error message and allow the user to enter a new value.

  • A palindrome is a sequence of characters that reads the same backward as forward. For example,...

    A palindrome is a sequence of characters that reads the same backward as forward. For example, each of the following five-digit integers is a palindrome: 12321, 55555, 45554 and 11611. Write an application that reads in a five-digit integer and determines whether it's a palindrome. If the number is not five digits long, display an error message and allow the user to enter a new value.

  • Problem 1. A palindrome is a sequence of characters that reads the same backward as forward....

    Problem 1. A palindrome is a sequence of characters that reads the same backward as forward. For example, each of the following five-digit integers is a palindrome: 12321, 55555, 45554 and 11611. Write an application that reads in a five-digit integer and determines whether it is a palindrome. If the number is not five digits long, display an error message and allow the user to enter a new value. Problem 2. Modify the program to determine whether a seven-digit number...

  • A palindrome is a sequence of characters that reads the same backwards as forward. For example,...

    A palindrome is a sequence of characters that reads the same backwards as forward. For example, each of the following five-digit integers is a palindrome: 12321, 55555, 45554, and 11611. Create an application that accepts a five-digit integer and determines whether it's a palindrome. Assume the user will enter only five digits, and never enter 0 as the first digit. I need the answer in visual studios please.

  • Write an application (SpaceDigits) that: (in java) a. inputs one number consisting of five digits from...

    Write an application (SpaceDigits) that: (in java) a. inputs one number consisting of five digits from the user, separates the number into its individual digits and prints the digits separated from one another by three spaces each. For example, if the user types in the number 42339, the program should print “4 2 3 3 9.” (Hint: The number input is five digits long, dividing it by 10000 gives the leftmost digit. digit1 = number / 10000 ) b. determines...

  • how to solve this on c++? Write a program that reads a five digits integer, then...

    how to solve this on c++? Write a program that reads a five digits integer, then swaps the unit position digit with the ten thousandth position digit, also swap the tenth position digit with the thousandth position digit. Print the new number For example if the number is 37846 then the new number is 64873. Sample input / output: nter a five digits integer The new form of the number 37846 is 64873

  • Using Windows Form App create an application that determines if an entry from the user is...

    Using Windows Form App create an application that determines if an entry from the user is a palindrome. A palindrome is a series of numbers that can be read from left to right or right to left. Examples of palindromes are 22222, 12321 and 89298. A palindrome must be 5 digits long. Using modulus and division evaluate digits one at a time from right to left. The user should enter their palindrome into the palindrome checker application using a text...

  • Does someone know how to solve this in java code? I'm taking programming level 1 Write...

    Does someone know how to solve this in java code? I'm taking programming level 1 Write a program that prompts the user to enter a three-digit integer and determines whether it is a palindrome number. A number is palindrome if it reads the same from right to left and from left to right.  

  • in python only 15. Write a program that reads a five-digit positive integer and breaks it...

    in python only 15. Write a program that reads a five-digit positive integer and breaks it into a sequence of individual digits. For example, the input 16384 is displayed as 16384

  • Write a Java program to convert octal (integer) numbers into their decimal number equivalents (exactly the...

    Write a Java program to convert octal (integer) numbers into their decimal number equivalents (exactly the opposite of what you have done in Assignment 4). Make sure that you create a new Project and Java class file for this assignment. Your file should be named “Main.java”. You can read about octal-to-decimal number conversions on wikepedia Assignment 4 is at the bottom Objective Your program should prompt the user to enter a number of no greater than 8 digits. If the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT