Question

In: Computer Science

(Palindrome number - A number is a palindrome if it reads the same from right to...

(Palindrome number - A number is a palindrome if it reads the same from right to left and from left to right, for example 676 is a palindrome number) Write a program that prompts the user to enter a three-digit integer number and determines whether it is a palindrome number or not

In Java Please

Solutions

Expert Solution

/************ Palindrome.java *************/

import java.util.Scanner;

public class Palindrome {

   public static void main(String[] args) {
       int number;

       /*
       * Creating an Scanner class object which is used to get the inputs
       * entered by the user
       */
       Scanner sc = new Scanner(System.in);

       while (true) {
           // Getting the input entered by the user
           System.out.print("Enter a three difit number :");
           number = sc.nextInt();
           if (number < 100 || number > 999) {
               System.out
                       .println("** Invalid.Must be a three digit number **");
           } else {
               break;
           }
       }

       boolean b = isPalindrome(number);
       if (b) {
           System.out.println(number + " is a palindrome");
       } else {
           System.out.println(number + " is not a palindrome");
       }

   }

   private static boolean isPalindrome(int number) {
       // Declaring variables
       int temp = 0, val;
       int reverse_number = 0;
       val = number;
       // This while loop will reverse the number
       while (number > 0) {
           temp = number % 10;
           reverse_number = reverse_number * 10 + temp;
           number = number / 10;
       }

       if (val == reverse_number)
           return true;
       else
           return false;

   }

}

/*******************************************************/

/*******************************************************/

Output:

/*******************************************************/


Related Solutions

1. A is called a palindrome if it reads the same from left and right. For...
1. A is called a palindrome if it reads the same from left and right. For instance, 13631 is a palindrome, while 435734 is not. A 6-digit number n is randomly chosen. Find the probability of the event that (a) n is a palindrome. (b) n is odd and a palindrome. (c) n is even and a palindrome.
A is called a palindrome if it reads the same from left and right. For instance,...
A is called a palindrome if it reads the same from left and right. For instance, 13631 is a palindrome, while 435734 is not. A 6-digit number n is randomly chosen. Find the probability of the event that (a) n is a palindrome. (b) n is odd and a palindrome. (c) n is even and a palindrome.
A palindromic number reads the same both ways (left-to-right and right-to-left). The largest palindrome made from...
A palindromic number reads the same both ways (left-to-right and right-to-left). The largest palindrome made from the product of two 2-digit numbers is 9,009 = 91 × 99. The largest palindrome made from the product of two 3-digit numbers is 906,609 = 913 × 993. The largest palindrome made from the product of two 4-digit numbers is 99,000,099 = 9,901 × 9,999. 1. Write a function IN JAVASCRIPT to find the largest palindrome made from the product of two 7-digit...
A word that reads the same from left to right and right to left is a...
A word that reads the same from left to right and right to left is a palindrome. For example, "I", "noon" and "racecar" are palindromes. In the following, we consider palindromic integers. Note that the first digit of an integer cannot be 0. How many positive palindromic integers are 5-digit long and contain 7 or 8?
In C++: This is the problem: [(1)] A palindrome is a string that reads the same...
In C++: This is the problem: [(1)] A palindrome is a string that reads the same forwards as backwards. Using only a fixed number of stacks and queues, the stack and queue ADT functions, and a fixed number of int and char variables, write an algorithm to determine if a string is a palindrome. Assume that the string is read from standard input one character at a time. The algorithm should output true or false as appropriate [(2)] Let Q...
IN JAVA - [(1)] A palindrome is a string that reads the same forwards as backwards....
IN JAVA - [(1)] A palindrome is a string that reads the same forwards as backwards. Using only a fixed number of stacks and queues, the stack and queue ADT functions, and a fixed number of int and char variables, write an algorithm to determine if a string is a palindrome. Assume that the string is read from standard input one character at a time. The algorithm should output true or false as appropriate [(2)] Let Q be a non-empty...
making a python code for this: A palindrome is a sequence that reads the same backwards...
making a python code for this: A palindrome is a sequence that reads the same backwards as forwards. Numbers can also be palindromes if we consider their digits as a sequence, for example 12121 and 8228 are palindromes. We can find palindromes from an initial seed number using the reverse and add method: choose a number, reverse its digits and add it to the original. If the sum is not a palindrome (which means, it is not the same number...
A palindrome is a word or phrase, which reads the same backward or forward. Write a...
A palindrome is a word or phrase, which reads the same backward or forward. Write a program that prompts the user for a string of characters terminated by a period and determines whether the string (without the period) is a palindrome. IMP: Assume that the input contains only letters and blanks. Assume also that the input is at most 30 characters long. Use an array of characters of size 30 to store the input! Disregard blanks when deciding if the...
Foundation of Computer Science A palindrome is a string that reads the same forward and backward....
Foundation of Computer Science A palindrome is a string that reads the same forward and backward. 1. Describe an algorithm that determines whether a string of n characters is a palindrome. 2. Write its corresponding program using your favorite programming language.
2. Palindromes A palindrome is a word that reads the same forwards and backwards. For example,...
2. Palindromes A palindrome is a word that reads the same forwards and backwards. For example, \aibohphobia" (the irrational fear of palindromes) is a word that reads the same forwards and backwards. Write a function called isPalindrome() that accepts a string as a parameter and returns True if the string is a palindrome, False otherwise. Using the function you created, write a program Python home work Python
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT