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
Ber [7]
4 years ago
6

Write a recursive method that tests whether a string is a palindrome. It should return a boolean T or F depending on whether or

not the string is a palindrome,
Computers and Technology
1 answer:
Sveta_85 [38]4 years ago
8 0

Answer:

// program in java.

// library

import java.util.*;

// class definition

class Main

{

// recursive function to check palindrome

   public static boolean isPalin(String str){

// base case

     if(str.length() == 0 ||str.length()==1){

        return true;

     }

// if first character is equal to last

     if(str.charAt(0) == str.charAt(str.length()-1))

     {

     // recursive call

        return isPalin(str.substring(1, str.length()-1));

     }

     // return

     return false;

  }

  // main method of the class

public static void main (String[] args) throws java.lang.Exception

{

   try{

    // object to read input

Scanner scr=new Scanner(System.in);

System.out.print("Enter a string:");

 // read string from user

String myString =scr.nextLine();

 // call function to check palindrome

     if (isPalin(myString)){

        System.out.println("Given String is a palindrome");

     }

// if string is not palindrome

     else{

        System.out.println("Given String is not a palindrome");

     }    

   }catch(Exception ex){

       return;}

}

}

Explanation:

Read a string from user and assign it to variable "myString" with scanner object. Call the method isPalindrome() with string input parameter.In this method, if  length of string is 0 or 1 then it will return true(base case) otherwise it will call itself and compare first character with last character.If string is palindrome then function will return true else return false.

Output:

Enter a string:ababa                                                                                                      

Given String is a palindrome

You might be interested in
Which subexpression will be solved first in the given statement?
Crazy boy [7]

Answer:

If you dont buy terraria than im going to make mrbeast buy it for you

Explanation:

reeeeeeeeeeeeeeeeeeeee

4 0
4 years ago
Hello can you please help with this if you want to thank you!
nikklg [1K]

Answer:

hardware and software is the answer

8 0
3 years ago
Read 2 more answers
In what country did true printing first take place?
kow [346]
Germany. Johannes Guten in Mainz, Germany
7 0
3 years ago
Read 2 more answers
True / False<br> Registers are generally optimized for capacity instead of speed.
lbvjy [14]

Answer: False

Explanation:

Registers are not optimized for capacity they are for speed. Registers are small storage space which is used to hold the value required by the cpu for processing. For making the value available immediately to the processor we have registers. There are many different types of registers.

5 0
3 years ago
Hi im new and would like you to answer​
soldier1979 [14.2K]

Answer:

Explanation:yes

7 0
4 years ago
Other questions:
  • In a token ring system, how quickly is the token passed around the circuit? 50 times per second millions of times per second hun
    11·1 answer
  • Sal Kan earned $3,000.00, But he is only getting $1,585.00 on his pay check to
    9·1 answer
  • On which tab can you find the margins button
    14·2 answers
  • Your computer is taking longer than usual to open files and you notice that your hard drive light stays on longer than usual. wh
    5·2 answers
  • You are asked to add speech to a robotic receptionist that sits at the front desk of a large organization. The robot has an anim
    10·2 answers
  • You have created a new DHCP scope with address range 192.168.1.1 to 192.168.1.254. You have five servers configured with static
    8·1 answer
  • At the Transport layer of the OSI, what is used to find and communicate with a particular application running on a host?
    7·1 answer
  • When do you use FTP?
    10·2 answers
  • The the concept of plug-and-play is demonstrated by which of the following scenarios
    14·2 answers
  • Differentiate between Computer Science and Information Technology
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!