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
__________ contain(s) remnants of word processing documents, e-mails, Internet browsing activity, database entries, and almost a
sergey [27]

<u>Swap files </u>contain(s) remnants of word processing documents, e-mails, Internet browsing activity, database entries, and almost any other work that has occurred during past Windows sessions.

Explanation:

I order to simulate extra space an operating system like windows use hard disk space in order to stimulate extra memory.When a computer system is running low with the memory space the swap file swaps a section of RAM onto the hard disk in order to obtain a free memory space.

This Process at times results in  slowing down of the computer  computer considerably.

<u>The combination of RAM and swap files is known as virtual memory.</u>

It is due to the  use of virtual memory that our computer is able to  run more programs than it could run in RAM alone.

4 0
3 years ago
Memory of the computer is measured by the following units which is = to 1 character
andrey2020 [161]

Memory of the computer is measured by the following units:

                                    Unit  

1 Kilobyte (KB)     1 KB = 1024 Bytes

2 Megabyte (MB)    1 MB = 1024 KB

3 GigaByte (GB)   1 GB = 1024 MB

4 TeraByte (TB)    1 TB = 1024 GB

<h3>In what unit is the computer memory  said to be measured?</h3>

Computer storage and memory is one that can be measured  by the use of units such as megabytes (MB) and gigabytes (GB) as well as others.

Hence, Memory of the computer is measured by the following units:

                                    Unit  

1 Kilobyte (KB)     1 KB = 1024 Bytes

2 Megabyte (MB)    1 MB = 1024 KB

3 GigaByte (GB)   1 GB = 1024 MB

4 TeraByte (TB)    1 TB = 1024 GB

Learn more about Memory from

brainly.com/question/24688176

#SPJ1

4 0
2 years ago
Complete the sentence.
julsineya [31]

Answer:

An internal server error

5 0
3 years ago
Help helppppppppppppp
SOVA2 [1]
Dont click the link
6 0
3 years ago
Question 3 (2 points)
jeyben [28]

Answer:

The energy source that does not use heat in the process of converting it to electricity is;

c. Sunlight

Explanation:

In converting Sunlight energy source to electricity, the photons in the light from the Sun excite electrons in the solar cells silicon layers, such that the electrons travel from n-type silicon layer to the p-type silicon layer creating electric potential energy that does work as the electrons flow back in the form of electricity from the p-type to the n-type silicon layer through an external circuit

7 0
3 years ago
Other questions:
  • Neighbor discovery performs many of the functions that icmp router discovery and icmp ____ handled in ipv4.
    13·1 answer
  • An employee believes there is an imminent danger situation at her workplace. She contacts OSHA to report the safety hazard. Her
    8·1 answer
  • . Convert BAC4 from hexadecimal to decimal. Show your work.
    9·1 answer
  • Describe how you would switch between the virtual consoles provided by Fedora.
    10·1 answer
  • Shawn works at the local electrical company in Nampa, ID, which provides electricity to the entire city of Boise. This area is p
    14·1 answer
  • List 5 uses of computer​
    9·1 answer
  • Qué es una magnitud eléctrica
    12·1 answer
  • PLEASEEE HELPPP im gonna cry
    11·2 answers
  • Swapping Order of Vowels Write a program to swap the order of the vowels in a given word. For example, if the word is programmin
    10·1 answer
  • _________ is an alternative name for the main memory.help me​
    14·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!