answer.
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
ladessa [460]
2 years ago
10

Write a recursive method called isReverse that accepts two strings as parameters and returns true if the two strings contain the

same sequence of characters as each other but in the opposite order (ignoring capitalization), and false otherwise. For example, the call of isReverse("hello", "eLLoH") would return true. The empty string, as well as any one-letter string, is considered to be its own reverse
Computers and Technology
1 answer:
Virty [35]2 years ago
3 0

Answer:

public static boolean isReverse(String s1, String s2)

{

if (s1.length() == 0 && s2.length() == 0)

{

return true;

}

else if (s1.length() == 0 || s2.length() == 0)

{

return false;

} else

{

String s1first = s1.substring(0, 1);

String s2last = s2.substring(s2.length() - 1);

return s1first.equalsIgnoreCase(s2last) &&

isReverse(s1.substring(1), s2.substring(0, s2.length() - 1));

}

}

public static boolean isReverse(String s1, String s2)

{

if (s1.length() != s2.length()) {

return false; // not same length

} else if (s1.length() == 0 && s2.length() == 0) {

return true;

} else

{

s1 = s1.toLowerCase();

s2 = s2.toLowerCase();

return s1.charAt(0) == s2.charAt(s2.length() - 1) &&

isReverse(s1.substring(1, s1.length()),

s2.substring(0, s2.length() - 1));

}

}

public static boolean isReverse(String s1, String s2)

{

if (s1.length() == s2.length())

{

return isReverse(s1.toLowerCase(), 0, s2.toLowerCase(), s2.length() - 1);

} else {

return false;

// not same length

}

}

private static boolean isReverse(String s1, int i1, String s2, int i2)

{

if (i1 >= s1.length() && i2 < 0) {

return true;

} else {

return s1.charAt(i1) == s2.charAt(i2) &&

isReverse(s1, i1 + 1, s2, i2 - 1);

}

}

public static boolean isReverse(String s1, String s2)

{

return reverse(s1.toLowerCase()).equals(s2.toLowerCase());

}

private static String reverse(String s)

{

if (s.length() == 0) {

return s;

} else {

return reverse(s.substring(1)) + s.charAt(0);

}

}

Explanation:

You might be interested in
Assume there is a class AirConditioner that supports the following behaviors: turning the air conditioner on and off. The follow
Dafna11 [192]

Answer:

1)

officeAC = new AirConditioner();

officeAC.turnOn();

2)

officeAC = new AirConditioner();

officeAC.turnOn();

officeAC.setTemp(69);  

Explanation:

1)

In the first statement a new object of the class AirConditioner whose reference is assigned to the officeAC. new is a keyword which creates an object of the class.

Next statement uses the method turnOn(). Reference to the new object officeAC is used to invoke this method turnOn().

2) The first two statements works the same as in 1)

The last statement invokes a method setTemp() using the reference variable and passes the value 69 to this method to set the desired temperature.

6 0
1 year ago
. Create a text file that contains your expenses for last month in the following categories: • Rent • Gas • Food • Clothing • Ca
Whitepunk [10]

Answer:

  1. from matplotlib import pyplot as plt
  2. with open("text.txt") as file:
  3.    data = file.readlines()
  4.    category = []
  5.    amount = []
  6.    for row in data:
  7.        values = row.split(" ")
  8.        category.append(values[0])
  9.        amount.append(float(values[1]))
  10.    
  11. figure = plt.figure()
  12. ax = figure.add_axes([0,0,1,1])
  13. ax.axis('equal')
  14. ax.pie(amount, labels = category, autopct='%1.2f%%')
  15. plt.show()

Explanation:

Firstly, we need to import matplotlib library (Line 1).

Next, open a file stream and use readlines method to read the data from the text file (Line 4). Presume the data read from the text files are as follows:

Rent 450

Gas 150

Food 500

Clothing 120

Car 600

Create two lists, category and amount (Line 5-6). Use a for loop to traverse through the read data and use split method to break each row of data into two individual items. The first item is added to category list whereas the second item is added to amount list (Line 7 - 10).

Next, create a plot figure and then add the axes (Line 12 - 13). We can use the pie method to generate a pie chart (Line 15) by setting the amount list as first argument and category list as value of labels attributes. The output pie chart can be found in the attachment.

7 0
2 years ago
Which of the following is a job that does not lend itself to telecommuting?
jonny [76]

Answer:

a car salesman who demonstrates the features of a new model of car

Explanation:

Telecommuting can be defined as the process or making use of a telephone, email, or the internet to achieve your daily work. An attorney that spends most of her time researching on the computer is making use of an internet to do her work and hence telecommuting is employed. A copywriter for an advertising firm also makes use of email in the process of write copying and hence telecommuting is employed. A telemarketer uses the telephone and a product support who handles queries sent by customers also uses the internet and emails and telephones and hence they all use telecommuting. Demonstrating the feature of a new car does not use require the use of a telephone, email, or the internet.

8 0
1 year ago
A company wants to inform a select list of it's regular customers about a flash sale. Which type of platform will it use to send
blondinia [14]
<h2>Answer :</h2>

In case of Flash Sale, usually company uses Instant messages or SMS. As there are chances customer in most of the cases don’t have access to their emails due to internet unavailability. However SMS can be directed towards customers without the requirements of an internet. In case of SMS, there are companies available that can shoot out targeted SMS based on cities or even an entire country at a very minimal price. Company can provided them there contacts as well as they have a list of numbers from different sources to which they can send instant messages.


5 0
2 years ago
As the network administrator for a growing isp, you want to make efficient use of your network addresses. one of the network add
lubasha [3.4K]

New Subnet Mask:

255.255.255.240

First 4 subnetwork Addresses:

197.14.88.0

197.14.88.16

197.14.88.32

197.14.88.48

6 0
2 years ago
Other questions:
  • What are threats to computer system
    6·1 answer
  • Replace the underlines with the words in parentheses that follow: the ____ solves the ____ of a ____ by expressing an ____ in a
    8·1 answer
  • Which is among the earliest formats of audio used in video games? A. MP3 B. wave table synthesis C. pulse code modulation D. MOD
    7·2 answers
  • Mobile computing has two major characteristics that differentiate it from other forms of computing. What are these two character
    8·1 answer
  • Write an expression that will cause the following code to print "18 or less" if the value of user_age is 18 or less. Write only
    9·2 answers
  • E-mail is an efficient means of disseminating information quickly and inexpensively. However, HIPAA regulations affect e-mail us
    13·1 answer
  • 3. Megan and her brother Marco have a side business where they shop at flea markets, garage sales, and estate
    9·1 answer
  • Given the macro definition and global declarations shown in the image below, provide answers to the following questions:
    5·1 answer
  • If a class has member variables that are pointers, you must ensure that you implement ____.
    6·1 answer
  • Through which of the devices listed are we able to connect to wireless networks? Check all that apply.
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!