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
What advantage does digital storytelling have over oral storytelling traditions?
Marysya12 [62]
Pretty sure the answer is D
6 0
4 years ago
Questions Presscomion
Alex787 [66]

Answer:

i dont get what you are trying to ask

Explanation:

7 0
4 years ago
Three materials needed to stream video video content
PIT_PIT [208]
Oh yeah yeah I don’t know ‍♂️ is
8 0
3 years ago
Read 2 more answers
Why might you receive a tax refund from the irs
Harrizon [31]
Im not quite sure but i got mine back yesterday soooo (pretty good)

8 0
4 years ago
Click cell i13 and calculate the agent commission using the base cost of the trip and a vlookup function that returns the commis
TiliK225 [7]
All you need to do is use excell.
5 0
3 years ago
Other questions:
  • Enter a nested lookup function in cell E4 that uses the cells E2 and E3 to return a specific sales record. For example, using th
    14·1 answer
  • Invention I chose was radio.
    9·1 answer
  • Which component of the Hyper-V architecture controls all communication with the physical hardware on the computer?
    8·1 answer
  • A TCP entity opens a connection and uses slow start. Approximately how many round-trip times are required before TCP can send N
    11·1 answer
  • What type of electronic monitoring involves an offender being contacted periodically by telephone or beeper to verify his or her
    5·1 answer
  • Dummy activities A. are found in both AOA and AON networks. B. are used when two activities have identical starting and ending e
    9·2 answers
  • What is hardware?
    10·1 answer
  • String member function compare compares two strings (or substrings) and returns 0 if:
    5·1 answer
  • SOMEONE HELP PLEASE ​
    5·1 answer
  • "Automated Deployment" is one of the prerequisite for DevOps implementation.
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!