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]
3 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]3 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
What is the importance of data validation, and how can user data entry errors be reduced or eliminated?
lisabon 2012 [21]

Incorrect data can lead to unexpected program execution results. Data entry errors can be reduced by only accepting valid input, e.g., if a number must be entered, alphabetic characters are ignored. After data validation, error messages can be prompted to the user, requiring him to enter the data again.

5 0
3 years ago
Which animation principle is applied to ‘sell’ the beginning of the character jump?
Sunny_sXe [5.5K]
Anticipation I think so but I’m not sure:)
3 0
2 years ago
Write a program that simulates picking a card from a deck of 52 cards. Your program should display the rank (Ace, 2, 3, 4, 5, 6,
Artyom0805 [142]

Answer:

Explanation:

The following is a python function that has arrays with all the cards available and then uses random to choose a random card from the dictionary. Finally it prints out the card chosen...

import random

def choose_card():

   card = ["Ace", 2, 3, 4, 5, 6, 7, 8, 9, 10, 'Jack', 'Queen', 'King']

   symbols = ['Clubs', 'Diamonds', 'Hearts', 'Spades']

   chosen_card = str(card[random.randint(0, len(card))])

   symbols = symbols[random.randint(0, len(symbols))]

   print("Chosen Card: " + chosen_card + " of " + symbols)

7 0
3 years ago
One advantage of using online note-taking tools is that they help students to
raketka [301]

Answer:

the correct answer is A

Explanation:

hope it helps

7 0
3 years ago
Read 2 more answers
What is the basic difference between x.509 and pgp in terms of key hierarchy and key trust?
ra1l [238]
In terms of key hierarchy, you have to request to a Certification Authority in order for them to issue you an X.509 certificate. On the other hand, you can creat your own pgp.

In terms of key trust, X.509 supports only a sole key owner. It can support only one digital signature to confirm the key's validity. This does not work for pgp.
3 0
3 years ago
Other questions:
  • The illustrations group contains all but a _______​
    9·1 answer
  • How to get administrator privileges on windows 7?
    13·1 answer
  • What is that black thing on my wall?
    9·1 answer
  • If you want to write some fancy interface on your computer with expanded communication to the Arduino, what library should you u
    13·1 answer
  • Visual imagery encoding relates to _____ encoding, in that a person is connecting the new information to previously existing inf
    11·1 answer
  • What task does the casting director do, apart from auditioning actors?
    8·1 answer
  • A function is executed when it is
    7·1 answer
  • The set of instructions that tell the computer what to do are called ____.
    13·2 answers
  • How many passes will it take to find the four in this list?
    15·2 answers
  • Please help I will mark brainliest
    11·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!