Question

In: Computer Science

Program 5: The concept of a 5-digit palindromenumber is a 5-digit number that reads the...

Program 5: 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.

Please HELP!!! Am I missing something...

import java.util.Scanner;

public class fiveDigitpalindrome {

   public static void main(String[] args) {

      int number = 0;

      Scanner input = new Scanner (System.in);

      System.out.print("Enter a 5-digit number: ");
      number = input.nextInt();
     
      if (number < 9999 && number > 10000) {
    
         int fiveDigits = 0, reverse = 0;
         int temp = number;
    
         while (temp > 0) {
            fiveDigits = temp % 10;
            reverse = (reverse * 10) + fiveDigits;
            temp = temp/10;
         } // end while loop
       
         if (number == reverse) {
            System.out.println("Judgement: Valid 5-digit palindrome.");
         } else
            System.out.println("Judgement: Invalid 5-digit palindrome.");
    
      }
      else
         System.out.println("Judgement: Invalid 5-digit number. Try Again!");
    
    

   }

}

Solutions

Expert Solution

import java.util.Scanner;

public class FiveDigitPalindrome {

    public static void main(String[] args) {

        int number = 0;

        Scanner input = new Scanner (System.in);

        System.out.print("Enter a 5-digit number: ");
        number = input.nextInt();

        if (number < 99999 && number > 10000) {

            int fiveDigits = 0, reverse = 0;
            int temp = number;

            while (temp > 0) {
                fiveDigits = temp % 10;
                reverse = (reverse * 10) + fiveDigits;
                temp = temp/10;
            } // end while loop

            if (number == reverse) {
                System.out.println("Judgement: Valid 5-digit palindrome.");
            } else
                System.out.println("Judgement: Invalid 5-digit palindrome.");

        }
        else
            System.out.println("Judgement: Invalid 5-digit number. Try Again!");



    }

}


Related Solutions

The number 52430 is a 5-digit number whereas 03201 is not a 5-digit number. Determine the...
The number 52430 is a 5-digit number whereas 03201 is not a 5-digit number. Determine the number of 5-digit multiples of 5 that can be created using the digits 0 to 9, if digits may not be repeated
Write a program that does the following: Prompts the user for a 5-digit number. Divides that...
Write a program that does the following: Prompts the user for a 5-digit number. Divides that number into its separate five digits. Adds up the sum of those five digits. Outputs that sum You should test your program with at least the following test cases. (I am to be programming with python) >>> RESTART: /Users/mamp/Desktop/Desktop - Enter a 5-digit number: 12345 15 >>> RESTART: /Users/mamp/Desktop/Desktop - Enter a 5-digit number: 00000 0 >>> RESTART: /Users/mamp/Desktop/Desktop - Enter a 5-digit number:...
in .java Write a program that reads an integer with 3 digits and prints each digit...
in .java Write a program that reads an integer with 3 digits and prints each digit per line in reverse order. Hint: consider what you get from these operations: 319%10, 319/10, 31%10, ... Enter an integer of exactly 3 digits(e.g. 538): 319 9 1 3 Hint: consider what you get from these operations: 319%10 319/10 31%10
Write a java program The last digit of a credit card number is the check digit,...
Write a java program The last digit of a credit card number is the check digit, which protects againts transaction errors. The following method is used to veryfy credit card numbers. For the simplicity we can assume that the credit card has 8 digits instead of 16. Follwing steps explains the algorithm in determining if a credit card number is a valid card.  Starting from the right most digit, form the sum of every other digit. For example, if...
Question 4: Set P to the largest digit in your 5 digit number. For example, if...
Question 4: Set P to the largest digit in your 5 digit number. For example, if your 5 digit number is 88412, then P should be set to 8. Calculate and print the value of (P+1) multiplied by itself (P+3) times. As an example, if your 5 digit number is 88412, you should print the result of multiplying 9 with itself 12 times -- this is also known as 9 to the power of 12. HINT: you are free to...
Assignment #2 will be the construction of a program that reads in an unspecified number of...
Assignment #2 will be the construction of a program that reads in an unspecified number of integers from standard input, performs some calculations on the inputted numbers, and outputs the results of those calculations to standard output. The numbers could be delimited by any kind of whitespace, i.e. tabs, spaces, and lines (Note that if you use the Scanner class, you do not have to worry about these delimiters. They will be taken care of). Your program will continue to...
PYTHON WHILE Write a program that prompts for and reads the number ? of spheres to...
PYTHON WHILE Write a program that prompts for and reads the number ? of spheres to be processed. If ?≤0 your program must display an error message and terminate; otherwise it does the following for ? times: Write a program that prompts for and reads the number ?n of spheres to be processed. If ?≤0n≤0 your program must display an error message and terminate; otherwise it does the following for ?n times: Prompts for and reads the volume of a...
Write a C program that reads an integer value. Assume it is the number of a...
Write a C program that reads an integer value. Assume it is the number of a month of the year; print out the name of that month (Hint: months need to be captured in an array).
(PYTHON) Lottery program. The program randomly generates a two-digit number, prompts the user to enter a...
(PYTHON) Lottery program. The program randomly generates a two-digit number, prompts the user to enter a single two- digit number, and determines whether the user wins according to the following rules. Write a loop to let the user play as many times as the user wanted. Use a sentinel or flag to quit out of the loop. 1.if the user’s input matches the lottery In the exact order, the award is $10,000. 2.if all the digits in the user’s input...
what is the best code to construct a C++ program that finds a five digit number;...
what is the best code to construct a C++ program that finds a five digit number; This number should reverses the order of its digits when multiplied by four. Also, how many five digits numbers are there in which the sum of the digits is even.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT