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:...
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...
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...
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...
Write a Java program that prompts for and reads the number N of cities or locations...
Write a Java program that prompts for and reads the number N of cities or locations to be processed. It then loops N times to prompt for and read, for each location, the decimal latitude, decimal longitude, and decimal magnetic declination. It then computes and displays, for each location, the Qibla direction (or bearing) from Magnetic North. The true bearing from a point A to a point B is the angle measured in degrees, in a clockwise direction, from the...
in java Write a program that reads in ten numbers and displays the number of distinct...
in java Write a program that reads in ten numbers and displays the number of distinct numbers and the distinct numbers separated by exactly one space (i.e., if a number appears multiple times, it is displayed only once). (Hint: Read a number and store it to an array if it is new. If the number is already in the array, ignore it.) After the input, the array contains the distinct numbers. Here is the sample run of the program: Enter...
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.
Lab 5 a) Write a program that reads in an unsigned integer K and sums the...
Lab 5 a) Write a program that reads in an unsigned integer K and sums the first K many integers that are divisible by 7. You should output the sum on a formatted manner b)Consider the following diamond it is an 11 by 11 diamond made with * signs. Write a program that takes as input positive odd integer K (greater than or equal to three and outputs a K by K diamond made with * signs * *** *...
Convert the following text into a code format: The program reads an unspecified number of integers...
Convert the following text into a code format: The program reads an unspecified number of integers until a zero is entered. While the program reads each number it counts the number of positive numbers and the number of negative numbers that have been entered and sum up the values of the numbers entered. After the user enters zero, the program computes the average of the input values, not counting the zero. At the end, the program displays the average, and...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT