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 happens if a sequence is out of order?
andre [41]

Answer:

If you are trying to put the events in order and they are out of order you will probaly get the question wrong so make sure the events are in order.

Explanation:

6 0
3 years ago
Read 2 more answers
The ___ provide(s) shortcuts to commonly used elements
Genrish500 [490]

The quick access toolbar provides shortcuts to commonly used elements.

The Home Tab brings you to the home page and the File Tab allows you to save the file or print it.

I hope this helps! :)

7 0
3 years ago
Read 2 more answers
I had no computer-related problems.
padilas [110]
Ummmmmmm A, agree???
8 0
3 years ago
Read 2 more answers
what are "open source" programming language? Give examples of open source languages. Discuss the pros and cons of open source la
m_a_m_a [10]

Answer:

  The open source is the programming language that basically falls inside the parameters of the protocol of open-source convention. This fundamentally implies the language are not proprietary, with the specific arrangements (contingent upon the open source permit), can be adjusted and based upon in a way that is available to general society.

The python and ruby are the main examples of the open source programming language.

The disadvantage of the open source is that it is not much compatible as compared to all other software. It is not user friendly and easy for using the software.

The advantage of the open source programming is that it is available at low cost and it has high availability.

6 0
3 years ago
Which option is used in Access to locate and retrieve data that may be present in multiple database tables within the database?
rosijanka [135]

Answer:

subroutines

Explanation:

subroutines is used in access to locate and retrieve data

5 0
3 years ago
Other questions:
  • When recording data on a multiple-disk storage system, should we fill a complete disk surface before starting on another surface
    6·1 answer
  • What is the most important external issue when using social media in emergency management?
    6·1 answer
  • Which design principle will help me add an element of interest in my poster by avoiding confusion and monotony?
    7·1 answer
  • why are the ads you might see on tv between 8am and 10am usually not the same ads you would see between 8pm and 10pm?
    12·1 answer
  • Unless grunkle stan pines is mistaken, there is a family of deer’s in his garden
    6·1 answer
  • You have a large TCP/IP network and want to keep a host's real time clock synchronized. What protocol should you use?
    10·1 answer
  • Define the missing function. licenseNum is created as: (100000 * customID) licenseYear, where customID is a function parameter.
    12·1 answer
  • You want to upgrade a server by installing an external SCSI tape drive. The system currently has a SCSI card and an internal SCS
    14·1 answer
  • A computer program that enables users to create and work with files and folders is called what?
    8·2 answers
  • It refers to the story or events in which the film revolves.
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!