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]
3 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]3 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 is the central unit of the computer that contains the logic circuitry and carries out the instructions of the computer's pr
weqwewe [10]
Well, it's called Central Processing Unit, or CPU.
8 0
4 years ago
C - Language Write three statements to print the first three elements of array runTimes. Follow each statement with a newline. E
Jobisdone [24]

Answer:

Replace

/* Your solution goes here */

with

printf("%d",runTimes[0]);

printf("%d",runTimes[1]);

printf("%d",runTimes[2]);

Explanation:

The question requires that the first three elements of array runTimes be printed;

The first three elements are the elements at the first, second and third positions.

It should be noted the index of an array starts at 0;

  • So, the first element has 0 as its index
  • The second has 1 as its index
  • The third has 2 as its index

So, to make reference to the first three elements, we make use of

<em>runTimes[0], runTimes[1] and runTimes[2]</em> respectively

Having mention the above;

It should also be noted that array is of type integers;

So, to display integers in C, we make use of "%d";

Hence, the print statement for the first three elements is

printf("%d",runTimes[0]);

printf("%d",runTimes[1]);

printf("%d",runTimes[2]);

8 0
3 years ago
What if you have been asked to opt or design expert system or virtual reality using artificial intelligence for your daily/routi
algol13

Answer:

I would design the word asa better place

Explanation:

6 0
3 years ago
How often should you typically monitor your checking account? Yearly Daily Every three months Monthly
Maslowich
I’d say monthly. It probably wouldn’t kill you to do it every three months though.
7 0
3 years ago
Read 2 more answers
True or False? Wireless connections that use a higher frequency are faster but have a shorter range.
Rudiy27

Answer:

it's a True statement

6 0
3 years ago
Other questions:
  • You are logged in as a user with limited system privileges, you are the linux system administrator and you have the password to
    5·1 answer
  • 1. How does inertia affect a person who is not wearing a seatbelt during a collision? 
    14·2 answers
  • Which method deletes a footer from a document?
    13·2 answers
  • How to solve 3(x - 2) = 9x<br><img src="https://tex.z-dn.net/?f=3%28x%20-%202%29%20%3D%209x" id="TexFormula1" title="3(x - 2) =
    14·1 answer
  • Write a function safeOpen() that takes one parameter, filename — a string giving the pathname of the file to be opened for readi
    15·1 answer
  • Adobe reader is a type of​
    14·2 answers
  • What is the main difference between project tasks and client support tickets?
    11·1 answer
  • (b) Cell B12 contains the formula, ROUND((SUM(B5:B9)*D1),1).
    15·1 answer
  • Phoebe is a Counselor who is trying to schedule a meeting with one of her patients. Which best describes an inappropriate locati
    10·2 answers
  • If you anticipate running a particular query often, you can improve overall performance by saving the query in a special file ca
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!