1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
DiKsa [7]
3 years ago
9

(Palindrome integer) Write the methods with the following headers // Return the reversal of an integer, i.e., reverse(456) retur

ns 654 public static int reverse(int number) // Return true if number is a palindrome public static boolean isPalindrome(int number) Use the reverse method to implement isPalindrome. A number is a palindrome if its reversal is the same as itself. Write a test program that prompts the user to enter an integer and reports whether the integer is a palindrome.
Computers and Technology
1 answer:
Debora [2.8K]3 years ago
7 0

Answer:

import java.util.Scanner;

public class PalindromeInteger {

public static void main(String[] args) {

 // Create an object of the Scanner class to allow for user's inputs

 Scanner input = new Scanner(System.in);

 // Create a prompt to display the aim of the program.

 System.out.println("Program to check whether or not a number is a palindrome");

 // Prompt the user to enter an integer number.

 System.out.println("Please enter an integer : ");

 // Receive user's input and store in an int variable, number.

 int number = input.nextInt();

 // Then, call the isPalindrome() method to check if or not the

 // number is a  palindrome integer.

 // Display the necessary output.

 if (isPalindrome(number)) {

  System.out.println(number + " is a palindrome integer");

 }

 else {

  System.out.println(number + " is a not a palindrome integer");

 }

}

// Method to return the reversal of an integer.

// It receives the integer as a parameter.

public static int reverse(int num) {

 // First convert the number into a string as follows:

 // Concatenate it with an empty quote.

 // Store the result in a String variable, str.

 String str = "" + num;

 // Create and initialize a String variable to hold the reversal of the  

 // string str. i.e rev_str

 String rev_str = "";

 // Create a loop to cycle through each character in the string str,

 // beginning at  the last character down to the first character.

 // At every cycle, append the character to the rev_str variable.

 // At the end of the loop, rev_str will contain the reversed of str

 for (int i = str.length() - 1; i >= 0; i--) {

  rev_str += str.charAt(i);

 }

 // Convert the rev_str to an integer using the Integer.parseInt()

 // method.  Store the result in an integer variable reversed_num.

 int reversed_num = Integer.parseInt(rev_str);

 // Return the reversed_num

 return reversed_num;

}

// Method to check whether or not a number is a palindrome integer.

// It takes in the number as parameter and returns a true or false.

// A number is a palindrome integer if reversing the number does not

//  change the  number itself.

public static boolean isPalindrome(int number) {

 // check if the number is the same as its reversal by calling the

 //reverse()  method declared earlier. Return true if yes, otherwise,

               // return false.

 if (number == reverse(number)) {

  return true;

 }

 return false;

}

}

Explanation:

The source code file for the program has also been attached to this response for readability. Please download the file and go through the comments in the code carefully as it explains every segment of the code.

Hope this helps!

Download java
You might be interested in
What is another word for microchips operating systems input methods and everything in between?
lord [1]
The answer is computer. A computer is made up of microchips (CPU and GPU), an operation system (macOS or Windows), input methods (keyboard and mouse), and other parts.
7 0
3 years ago
Julie: 3: 36, 6:72, 9:108....tell me the next 3 ratios * math*
svlad2 [7]

Answer:

12:144, 15:180,

Explanation:

8 0
3 years ago
ou have a company network that is connected to the internet. You want all users to have internet access, but you need to protect
Rus_ich [418]

Server and network is 2 different things, just put the server on a different network.  ;) duh

Explanation:

4 0
2 years ago
When should the sponsor-monitor conduct the most detailed review of the study protocol with the site's study staff?
Likurg_2 [28]

Answer:

Site initiation visit is the correct answer.

Explanation:

Because the SIV is the sponsor-monitor which administers the detailed analysis of the site's study staff by the study protocol and it observes the process of the visite over a while that it take place after the visite of the site section. It also needed to set up the research site to administrates the analysis. So, that's why the following answer is true.

8 0
2 years ago
A special case of the non-inverting amplifier is when
Aneli [31]

Answer:

c-Either A or B

Explanation:

The non-inverting amplifier usually has the input voltage connected to the non-inverting input while the inverting input is connected to the output.

Both the unit gain amplifier and the voltage follower have an input voltage connected to the non-inverting input, and the inverting input connected to the output, so both are special cases of the non-inverting amplifier.

The correct answer is

c-Either A or B

4 0
3 years ago
Other questions:
  • Which of the following is an important initial step in designing an interface
    7·1 answer
  • Which type of communication protocol converts data into standard formats that can be used by applications?
    11·1 answer
  • .When an argument is passed ______________, the called method can access and modify the caller’s original data directly.
    8·1 answer
  • "the most common way to access the internet is through ________."
    5·1 answer
  • What element of a timeline helps to mark progress of the project?
    15·1 answer
  • 1.Which type of camera tool pushes the picture back and makes it wider, exaggerating the distance between the background and for
    13·2 answers
  • Is your florida learners license number the same as the actual license number?
    14·2 answers
  • E-mail has made it very easy to send a message to more than one person at any time of day from just about anywhere. If you wante
    12·2 answers
  • Hey guys im just curious.... whats ur favorite number
    6·2 answers
  • When you pass a double variable to a method, the method receives ______.a) a copy of the memory addressb) the reference of the v
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!