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]
2 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]2 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
How many inputs are included in the following requirement? REQUIREMENT: Write a program that asks the employee for their age. Th
wolverine [178]

Answer:

The correct answer for the given question is 1

Explanation:

Following are the program in c language  

#include<stdio.h> // header file

#include<conio.h>  //header file

void main()  // main method

{

int age,retiredAge;  // variable

clrscr();  // clear screen

printf("Enter Age : ");

scanf("%d",&age);  // input age

printf("************************");

retiredAge = (65-age);  // calculating retired age

printf("\nYour Age is %d",age);

if(retiredAge<0)  // checking condition

{

printf("\nYou are already cross the retired age. Or Enter Invalid Age.");

}

else

{

printf("\nNo of Years Left to retired is %d",retiredAge);  // dsiplay age

}

getch();

}

Output:

Enter Age : 50

************************

Your Age is 50

No of Years Left to retired is 15

Here Age is the only required input to calculate the retirement age of employee. if entered age is greater than 65 then a message is printed " You are already cross the retired age. Or Enter Invalid Age. " if entered age is valid then retiredAge is calculated with the formula retiredAge = (65-age). and finally display the age,followed by the number of years left to retirement.

Therefore  1 input are required for the above program.

4 0
2 years ago
which of the following peripheral does not belong to a group: A) Monitor B) Printer C) Hardware D) Keyboard​
nikdorinn [45]
C hardware is the correct answer
5 0
3 years ago
Which one of the following statements most fully describes the general capabilities of desktop publishing software?
OleMash [197]
The answer is B.
<span> desktop publishing program must be able to take text and graphics from a number of sources and allow these elements to be arranged on a page. 
The main purpose of a destkop publishing program is to aid user in creating documents using its page layout so it could generate printable media with higher quality compared to the one that is handmade.</span>
7 0
3 years ago
This is not what I asked for​
jolli1 [7]
?? What does that mean? What is the question
3 0
2 years ago
Select the items that can be measured.
Slav-nsk [51]

Answer:

distance

capacity

smoothness

thickness

4 0
2 years ago
Read 2 more answers
Other questions:
  • 1. _______ is when two things happen at one time when using the Scratch program.
    6·1 answer
  • Which of the following statements is false?
    12·1 answer
  • What is the smallest unit of data on the hard drive?
    5·1 answer
  • Once artwork is inserted into a placeholder, it can be moved around on a slide. True False
    9·1 answer
  • A stateless firewall inspects each incoming packet to determine whether it belongs to a currently active connection.
    9·1 answer
  • The most common clefs for high notes are what?
    6·2 answers
  • Anyone know how to fix black screen of death on computer​
    6·1 answer
  • Something I should look for when trying to decide if a source is credible is the publication's ....
    10·1 answer
  • Direction: Read each item carefully and choose the letter of the correct answer. Write your answers on a separate sheet of paper
    12·1 answer
  • If a company saw an online photo of you playing basketball, it might try to sell
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!