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]
4 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]4 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
You created an outline within a worksheet. what does the button indicate to the left of a row heading?
cricket20 [7]
<span>Business Name (default field), State (correct field)</span>
3 0
3 years ago
What are the steps involved in accepting all the changes in a document?
Makovka662 [10]

To accept all the changes in a document click Accept All.

4 0
3 years ago
Read 2 more answers
In this image, we are clicking a button on the Quick Access Toolbar. What will happen
Lostsunrise [7]

Answer: It’s B The presentation will start from the beginning

Explanation: I took the test

7 0
3 years ago
During email encryption, the system creates which type of key to allow the user to send an encrypted email?
kiruha [24]
A hope this is correct just read an article on it
5 0
3 years ago
Read 2 more answers
A common text feature is,
Umnica [9.8K]
The answer would be D the summary
4 0
3 years ago
Other questions:
  • This program will output a right triangle based on user specified height triangle_height and symbol triangle_char. (1) The given
    9·1 answer
  • Suppose we provide a new implementation of the transport layer protocol tcp providing the same functionality using different alg
    14·1 answer
  • Direct solar power is when:
    6·1 answer
  • Escribe, en los siguientes cuadros, los conceptos que correspondan
    10·1 answer
  • Care should be taken whenever you post comments or photos to any social media or other websites, because each of these online ac
    8·1 answer
  • Which of the following terms best describes the security domain that relates to how data is classified and valued?
    14·1 answer
  • When are computers most vulnerable to threats or damage?
    9·1 answer
  • What are some of these new iPad extras? One is the iMarker. Crayola teamed up with another company to make it. It costs $29.99.
    8·1 answer
  • WILL GIVE BRAINLIEST!!!!!!!
    15·2 answers
  • Cars are only as safe as their driver, so __ is your bet to lower your risk.
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!