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
Lelu [443]
4 years ago
11

Fill in the code to complete the following method for checking whether a string is a palindrome. public static boolean isPalindr

ome(String s) { if (s.length() <= 1) // Base case return true; else if ________ return false; else return isPalindrome(s.substring(1, s.length() - 1)); }
Computers and Technology
1 answer:
Ilia_Sergeevich [38]4 years ago
4 0

Answer:

(s.charAt(0) != s.charAt(s.length()-1))

Explanation:

public class Palindrome

{

public static void main(String[] args) {

   

    System.out.println(isPalindrome("car"));

    System.out.println(isPalindrome("carac"));

 

}

   public static boolean isPalindrome(String s) {

       if (s.length() <= 1)

           return true;

       else if (s.charAt(0) != s.charAt(s.length()-1))

           return false;

       else

           return isPalindrome(s.substring(1, s.length() - 1));

   }

}

You may see the whole code above with two test scenarios.

The part that needs to be filled is the base case that if the character at position 0 is not equal to the character at the last position in the string, that means the string is not a palindrome. (If this condition meets, it checks for the second and the one before the last position, and keeps checking)

You might be interested in
What two things can you do to display the entire content of a cell? ​
Svet_ta [14]
Dissect and make sure that I don’t onow the answer sorry brother
4 0
3 years ago
Discuss four uses of computer ​
PtichkaEL [24]

1. It helps to the development of our career.

2. Through the internet, we can know the facts which were happening all over the world

3. Computer can be use as a calculator too

4. We can store any kind of information.

<h3>Hope This Helps You ❤️</h3>
6 0
3 years ago
Read 2 more answers
What is the one common feature that ties together different social media technologies? All of the social media tools we use toda
xxTIMURxx [149]
They provide an intersection between technology, social interaction, and the sharing of information
8 0
3 years ago
Read 2 more answers
Which statement will you use to create a scanner object scan to read input from the keyboard
vlabodo [156]

Answer:

<em><u>To create a Scanner object, you use the new keyword. To create a Scanner object that gets input from the keyboard, specify System.in in the parentheses. To use one of the methods of a Scanner object, code the object name, a dot (period), the method name, and a set of parentheses.</u></em>

8 0
3 years ago
Netiquette is the
e-lub [12.9K]

Answer:

C

Correct or acceptable way of communicating

4 0
3 years ago
Other questions:
  • Which of the following is a benefit, as well as a risk, associated with client/server networks?
    8·2 answers
  • What do you think of explaining to young people, from high school, the legitimacy of copyright and the dangers they can run on t
    11·1 answer
  • Slmething about device for defrosting windscreen?
    5·1 answer
  • What adds the element carbon to the environment
    10·2 answers
  • Which of the following are examples of how a company might use consumer data it had collected? a To decide what types of product
    10·1 answer
  • When circuit switching is used, what is the maximum number of circuit-switched users that can be supported?
    7·1 answer
  • If you decide you want to meet someone you met online, what should you do first? A. Tell your best friend. B. Call the person yo
    12·1 answer
  • It is an electronic device that capable of accessing accepting processing product and storing data​
    13·1 answer
  • Anyone here codes? <br> C++, C#, Lua? Anything?
    15·2 answers
  • Software that allows users to use and adapt it for any purpose, often allowing the public to participate in further development
    7·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!