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
Juliette [100K]
3 years ago
13

Write a method that checks whether the input string or a sentence (a string with spaces) is a palindrome or not. The method shou

ld be case insensitive and should ignore spaces. Write a test program that prompts the user to input a string and invokes this method. Some example runs are: Enter the input string: madam Input string madam is a palindrome Enter the input string: banana Input string banana is NOT a palindrome Enter the input string: Race Car Input string Race Car is a palindrome Enter the input string: Too HOT to hoot Input string Too HOT to hoot is a palindrome
Computers and Technology
1 answer:
AURORKA [14]3 years ago
5 0

Answer:

import java.util.Scanner;

public class Pallindrome {

   public static void main(String[] args) {

       Scanner in = new Scanner(System.in);

       System.out.println("Enter the input string: ");

       String word = in.nextLine();

       System.out.println(isPallindrome(word));

   }

   public static String isPallindrome(String word){

       String rev ="";

       int len = word.length();

       for ( int i = len - 1; i >= 0; i-- )

           rev = rev + word.charAt(i);

       if (word.equals(rev))

           return word+" is palindrome";

       else

           return word+ " is not palindrome";

   }

}

Explanation:

  • Create the method in Java to receive a String parameter
  • Using a for loop reverse the string
  • Use another for loop to compare the characters of the original string and the reversed string
  • If they are equal print palindrome
  • else print not palindrome
  • Within the main method prompt user for a sentence
  • Call the method and pass the sentence entered by user
You might be interested in
WILL GIVE BRAINLIST IF ANSWERED RIGHT 1. An engine's _______ contains the cylinder block, the cylinders, the piston, the connect
miss Akunina [59]
First three are c b and d
3 0
2 years ago
Read 2 more answers
What is the output of the following code? stackList stack; int x, y; x = 2; y = 3; stack.push(8); stack.push(x); stack.push(x +
Sunny_sXe [5.5K]

Stack is LIFO data structure (Last In First Out) where the last element entered in stack will be the last one to be out of stack. It has three operations: push() : used to insert an element in stack, pop() : used to delete an element from the stack, top() : used to return the top of the stack i.e. the newest member of the stack. All these operations will take place at the top.

<u>Explanation:</u>

Now, looking at the program, x and y are initialized the values of 2 and 3 respectively. The stack pushes 8 onto the stack making it the first member of the stack. Then the value of x which is 2 is pushed onto the stack. Next, (x+5) = (2+5) = 7 is pushed onto the stack.

Pop() is used to delete hence 7 is popped out from the stack. top() is assigned to y which is 2 in this case and again 2 is popped out from the stack. Now, (x+y) = (2+2) = 4 is pushed onto the stack. And the top() is assigned to x which is 4. 4 is again popped out from the stack. Hence the value of x is 4.

3 0
3 years ago
The number of colors available in a graphic is referred to as color what?
Drupady [299]
With 8<span> bits used to represent each color value, one pixel requires </span>24<span> bits. The number of colors available in a graphic is referred to as color depth. I hope you understand! :-)</span>
5 0
2 years ago
Pls help!!
alexira [117]

Answer:

4.24

Explanation:

First you find the mean of the data set, which is 7. Then to find standard deviation you have to follow the formula which tells you to subtract the mean from each number under the square root : √(2 - 7)^2 + (9 - 7)^2 + (10 - 7)^2 + (4 - 7)^2 + (8 - 7)^2 + (4 - 7)^2 + (12 - 7). Once you solve the parenthesis you square it, once you square it the negatives won't matter. That will leave you with this : √(25 + 4 + 9 + 9 + 25). The formula tells you to find the sum of those numbers (which is 72) then subtract one from how many numbers there are, 5 - 1 = 4, and divide your sum by that number. So 72 / 4 = 18. Then you find the square root of 18 and that becomes your answer.

7 0
2 years ago
A formula =A1+B2 is in cell D8. If you copy that formula to cell D9, what is the new formula in cell D9? A. '=A1+B2 B. '=A2+B3 C
Georgia [21]
It has to be B. Im sure of it.
6 0
3 years ago
Read 2 more answers
Other questions:
  • Access controls are enforced automatically in FMS service routines that access and manipulate files and directories.
    9·1 answer
  • True or false? You can test your marketing emails in different email clients from within the email editor.
    10·1 answer
  • What was one of the main purposes of the first computer systems?
    11·1 answer
  • Where should you look for most objective and unbaised information
    15·1 answer
  • An arrangement in which local businesses team up with schools, hiring students to perform jobs that use knowledge and skills tau
    9·2 answers
  • Jin needs to add a row into his spreadsheet, but he does not want to remove any existing data. Which combination of options shou
    6·2 answers
  • Software is the word for:
    15·1 answer
  • Select the correct answer from each drop-down menu.
    8·1 answer
  • Imagine that you just received a summer job working for a computer repair shop one of your first task is to take apart a compute
    14·1 answer
  • (09 MC)How can understanding your own personality improve your relationships with others?
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!