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
ladessa [460]
4 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]4 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
Which of the following criteria was a key milestone for the object-relational model created in the mid-1980s?
gladu [14]

The use of the inheritance to have a structure inherit attributes and methods of classes above it.


One of the key milestones in the period in which the object-relational model was created was the creation of a data
model that closely represented the real world. In this approach, objects were created in which both data and its
relationships were all contained in one place. These data models were becoming a norm to be stored on the web. They
also incorporated support for star schemas within data warehouses. Objects that had similar characteristics were
grouped into classes, where they had a shared structure of attributes and behaviors.

3 0
2 years ago
6. Larger Than n In a program, write a function that accepts two arguments: a list, and a number n. Assume that the list contain
Reika [66]

Answer:

The solution code is written in Python

  1. def largerThanN(myList, n):
  2.    output = ""
  3.    for x in myList:
  4.        if(x > n):
  5.            output += str(x) + " "
  6.    
  7.    print(output)
  8. l = [5, 12, 11, 4, 56, 32]
  9. n = 15
  10. largerThanN(l, n)

Explanation:

Firstly, create a function largerThanN that accepts two arguments, a list (myList) and a number (n) (Line 1).

Next, create a output variable to hold the string of numbers in the list that are greater than the input number n (Line 2).

Create a for loop to traverse through each number in the list and then check if the current x is bigger than n. If so concatenate the x to output string along with a single space " " (Line 4 -6)

After the loop, print the output string (Line 8)

We test the function by using a sample list and n = 15 (Line 10 - 12). The program will display 56 32 .

6 0
3 years ago
Suppose a package pkg1 contains a class named MyClass and another package pkg2 contains a different class named MyClass. What ha
pogonyaev

Answer:

Following are the solution to this question:

Explanation:

In this question, two packages "pkg1 and pkg2" is defined, that hold a class that is "MyClass", in which the class name is the same. If we import the package so, it can't import both classes in the very same file. If we really need to apply to both, then must completely specify one class name, and in the class name is different so, we simply use both classes by creating the instance.  

7 0
3 years ago
What is the difference between basic auth and oauth.
ratelena [41]

Answer:

Basic auth is an authentication where username and password are sent with an HTTP request unencrypted (just base64 encoded).

OAuth is a scheme whereby you perform a login at an IAM server, which gets you a token, and then you provide the token with requests to another server.

4 0
2 years ago
Joe is a computer service technician. People in his neighborhood usually depend on his suggestions for purchasing any computer a
ser-zykov [4K]

Answer:

C

Explanation:

Because he's knowledge ,everyone asking he's opinion if i am not wrong.

I hope i did help you on this questions

8 0
4 years ago
Read 2 more answers
Other questions:
  • Write a function so that the main() code below can be replaced by the simpler code that calls function MphAndMinutesToMiles(). O
    5·1 answer
  • After earning a learners license what test must be successfully passed to earn an operators license in Florida
    14·1 answer
  • What entity created the open systems interconnection (osi) seven-layer model?
    15·1 answer
  • How many occupational groups are there in the SOC system?
    12·1 answer
  • Which best describes the benefits of renting a home
    12·2 answers
  • Write a partial class that shows a class constant and an instance method. Write an instance method that converts feet to inches
    9·1 answer
  • Ayudaaaaa, Instale el software equivocado a mi tv westinghause con placa tp.Ms338.Pb801 y ahora queda en negro, ¿Cómo lo puedo s
    15·1 answer
  • Write the code to produce a for loop that counts down from 20 to 0 by 2’s and prints the number each time it goes through the lo
    15·1 answer
  • OMG 2 TIMES ;DDDDDDDDDDDDDDDDD​
    14·1 answer
  • _____ drives are storage drives that contain both solid-state storage and hard disks in an attempt to gain the speed and power o
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!