(Palindrome integer) Write the methods with the following headers // Return the reversal of an integer, i.e., reverse(456) returns 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.

Answers

Answer 1
Answer:

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!


Related Questions

what would be the address of the cell, which is intersect of the second row and third column in a worksheet
- If we place records from different tables in adjacent____________, it would increase efficiency of a database.Physical locationTableFormempty location
The section on the Publisher screen that allows you to quickly move from one page another in a publication is the _____. View tabPage panePage Design tabZoom bar
Write a function namedadd_complex that adds the correspondingnumbers of its arguments (both complexstructures), then returns the result (anothercomplex structure)
Outline 3 computer system problem that could harm people and propose the way avoid the problem​

What is the purpose of creating a PST file?Question 18 options:
a)To document an antivirus pattern that continues to be sent to your mailbox
b)To insert as a Signature for all outgoing emails
c) To save your emails so that you can restore your mailbox if necessary
d)To create a file that deleted emails will be sent to for deletion

Answers

The purpose of creating a PST file is to

c) To save your emails so that you can restore your mailbox if necessary

Explanation:

  • A PST file is a personal folder file in Microsoft Outlook. In Outlook, the storage limit for a single user's . PST file is 2 GB. PST stands for personal storage.
  • A PST file, or personal storage table (. pst) file, is a Microsoft Outlook Data File that stores a user's Outlook data for POP3, IMAP and web-based mail accounts, including all mail folders and the items within the folders, such as emails, email attachments, to do items and appointments, contacts and more.
  • In computing, a Personal Storage Table (. pst) is an open proprietary file format used to store copies of messages, calendar events, and other items within Microsoft software such as Microsoft Exchange Client, Windows Messaging, and Microsoft Outlook.
  • The purpose of the PST file was, like it is today, to provide end users with a way to create local archives of their server-based email.
  • As a result, PST files provided end users with a means of expanding their email storage by creating and maintaining one or more local archives.

Devices may be arranged in a _____ topology. A) mesh
B) ring
C) bus
D) all of the above

Answers

Answer:

ring

Explanation:

Identify a true statement about a flat file system. a. Data in a flat file system can be updated efficiently. b. Data in a flat file system may not be updated in all files consistently. c. Data duplication in a flat file system is very efficient. d. Data in a flat file system can be easily managed.

Answers

Answer:

The correct answer is D)

Data in a Flat File System can be easily managed.

Explanation:

When every file in the database is stored under a different name, it is often referred to as a Flat File System.

This system of filing is common with all Windows 95 computers and other operating systems since it's launch.

In a Flat File System, files are organised in a hierarchical file system with a hierarchy of directories and subdirectories, with every directory containing a certain number of files.

Cheers!

Consider the following definition of a recursive method. public static int mystery(int[] list, int first, int last) { if (first == last) return list[first]; else return list[first] + mystery(list, first + 1, last); } Given the declaration int[] alpha = {1, 4, 5, 8, 9}; What is the output of the following statement? System.out.println(mystery(alpha, 0, 4)); a. 1 b. 18 c. 27 d. 32

Answers

Answer:

c. 27

Explanation:

  • In recursion method, a method calls itself until a condition becomes true and returned back. In mystery(), at first time, first is 0 and last is 4. Condition is checked and 0!=4 so else part is executed in which again mystery is called with first as 1 and last 4. This will go again and again until first=4.
  • When first=4 it is also equal to last so if part is executed and alpha[4] is returned which is 9, now it comes alpha[3] +9 which is 8+9 =17 .
  • It is returning values to its previous calls that is why it will reduce to alpha[0]+alpha[1]+alpha[2]+17 which is nothing but sum of all elements of a alpha
  • Then, 1+4+5+8+9=27.

An objective function in linearprogramming is a(n):decisionvariable.
environmentvariable.
resultvariable.
independentvariable.
constant.

Answers

Answer: An objective function in linear programming is a decision variable.

Explanation: An objective function is a function which has the target towards the model whether it should be maximized or minimized according to the relation between the  variables present in the function. There are set of variables which are responsible for the controlling of objective function that is known as decision variables.

Write a program using integers user_num and x as input, and output user_num divided by x three times.Ex: If the input is:20002Then the output is:1000 500 250Note: In Python 3, integer division discards fractions. Ex: 6 // 4 is 1 (the 0.5 is discarded).LAB ACTIVITY2.29.1: LAB: Divide by x0 / 10main.pyLoad default template...12''' Type your code here. '''

Answers

Answer:

Following are the code to the given question:

user_num = int(input())#defining a variable user_num that takes input from user-end

x = int(input())#defining a variable x that takes input from user-end

for j in range(3):#defining for loop that divides the value three times

   user_num = user_num // x#dividing the value and store integer part

   print(user_num)#print value

Output:

2000

2

1000

500

250

Explanation:

In the above-given program code two-variable "user_num and x" is declared that inputs the value from the user-end and define a for loop that uses the "j" variable with the range method.

In the loop, it divides the "user_num" value with the "x" value and holds the integer part in the "user_num" variable, and prints its value.