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
Nathan would like to save his PowerPoint presentation as a video that can be replayed easily on any device at full quality. Whic
aniked [119]

Answer:

Presentation Quality

Explanation:

7 0
2 years ago
Ok so I know this is the most random question to ask on brainly, but does anyone know how to copy on placement in sims 4 for pc?
pochemuha

Answer:

yes i do i will tel you if you put brainlist

Explanation:

3 0
2 years ago
Read 2 more answers
What cultural characteristics does the Chicano mural movement reflect? Check all that apply.
Nataliya [291]

Answer: i believe it is family, religion, history, music and arts, and folklore.

Explanation:

8 0
3 years ago
Placing graphic material in the appendix is
Mrac [35]
Recommended when the graphics would make a report lengthy or the discussion complic-<span>ated to follow.</span>
8 0
3 years ago
Read 2 more answers
In a forest ecosystem, which of the following is the best example of a limiting factor for a rabbit population?
Verdich [7]

Answer:

A rise in the population of predators is followed by a decrease in the population of prey.

5 0
3 years ago
Other questions:
  • the task is to ask the user for three numbers and find the average which pseudocode gives you the comment outline for task​
    10·1 answer
  • Why should spain go to Africa ​
    15·1 answer
  • If the computer you are using is a laptop that moves from one network to another, you can click the _____ tab and configure stat
    7·1 answer
  • Is a book considered technology?
    8·2 answers
  • Quick!!!!!
    13·2 answers
  • To copy and paste the image in MS Word the dash option is used​
    9·1 answer
  • Consider the following statements: Statement A: In Duplex transmission, either node can transmit while the other node can receiv
    10·1 answer
  • Which of the following is a productivity strategy for collaboration?
    9·1 answer
  • Is it a way to get robuc 4 free
    6·2 answers
  • How is video compression accomplished?
    10·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!