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

Write a recursive method public static String reverse(String str) that computes the reverse of a string. For example, reverse("f

low") should return "wolf". Hint: Reverse the substring starting at the second character, then add the first character at the end. For example, to reverse "flow", first reverse "low" to "wol", then add the "f" at the end.
Computers and Technology
1 answer:
Aneli [31]4 years ago
5 0

Answer:

Explanation:

StringRecursiveReversal.java

public class StringRecursiveReversal {

   static String reverse1 = "";

   public static String reverse(String str){

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

           return str;

       } else {

           reverse1 += str.charAt(str.length()-1)

                   +reverse(str.substring(0,str.length()-1));

           return reverse1;

     }

   }

   public static void main(String a[]){

       StringRecursiveReversal srr = new StringRecursiveReversal();

       System.out.println("Result: "+srr.reverse("flow"));

   }

}

Output :

Result: wolf

You might be interested in
Given a long integer representing a 10-digit phone number, output the area code, prefix, and line number using the format (800)
Alexxandr [17]

Answer:

See explanation!

Explanation:

Here we have a program written in C++ language. Each // symbol is a relative comment explaining the reason for each command line (and is not included during the program execution).

<em>The Program: </em>

#include <iostream>

<em>//c++ build in library</em>

using namespace std;

<em>//main code body starts here</em>

int main()

{

 <em> //declare variable to store phone numbers,its area code, prefix and line    number.</em>

  long pnumber;   <em>//declare long variable</em>

  int ac, prefix, lnumber;

 <em> //declare integer variables, where ac: Area Code and lnumber is the Line Number</em>

  cout<<"Enter a 10-digit Phone Number: "<<endl;

  <em>//cout command prints on screen the desired message</em>

  cin>>pnumber;

 <em> //cin command enables the user to interact with the programm and enter information manually</em>

 <em> //main body to obtain the desired output starts below</em>

<em>   //each 'division' is used to allocate the correct value at the correct </em>

<em>   //since prefix is used to get the desired output of ( )    -</em>

  ac = pnumber/10000000;

  prefix = (pnumber/10000)%1000;

  lnumber = pnumber%10000;

 <em> //main body ends here</em>

  cout<<"Based on your 10-digit number"<<endl;

  cout<<"below you have (AreaCode), Prefix, and - line number "<<endl;

  cout<<"("<<ac<<")"<<""<<prefix<<"-"<<lnumber<<endl;

 <em> //Prints on screen the desired output of the long 10 digit Number</em>

  return 0;<em> //ends program</em>

}

-------------------------------------------------------------------------------------------------------

<em>The Output Sample:</em>

Enter a 10-digit Phone Number:

8019004673

Based on your 10-digit number

below you have (Area Code), Prefix, and - line number

(801) 900-4673

<em>....Programm finished with exit code 0</em>

8 0
3 years ago
Given:
777dan777 [17]

Answer:

Python Code:-

#creating a list  

current_members = [4, 6, 9]

#defining the variable  

#assigning the value

member_id = 9

#defining variable count

count = 0

#defining the variable and setting initial value to true

is_a_member = False

#for loop is used to iterate over the list  

for x in current_members:

  #if statement will check whether the element is found

  if x == member_id:

      #set the value to true if the value is matched  

      is_a_member = True

      #set the value to 1

      count = 1

#if count == 0

#set the value of is_a_member variable to false

if count == 0:

  is_a_member = False

#print the current value stored in is_a_member variable

print(is_a_member)

Explanation:

In the above python program, a list is created that is "current_members"  and some values are inserted. In the next line, a three-variable is defined that are member_id, count, and is_a_member.

  • In both variable member_id, count assigns some value. and in is_a_member variable assign a False value.
  • Using a for loop to iterate over the list.
  • Inside the loop, If the statement will check whether the element is found. Then set the value of is_a_member variable to True and count to 1.
  • Another if the statement is used which checks the value of the count variable. If the value of count is 0 then set the value of is_a_member to False.
  • print() function is used to display the current value of is_a_member variable.
6 0
4 years ago
Write a statement to create a Google Guava Multimap instance which contains student ids as keys and the associated values are st
Sergeu [11.5K]

Answer: provided in the explanation section

Explanation:

Note: take note for indentation so as to prevent error.

So we import com.google.common.collect.Multimap;

import java.util.Collection;

import java.util.Map;

class Main {

   public static void main(String[] args) {

       // key as studentId and List of Profile as value.

       Multimap<String,Profile> multimap = ArrayListMultimap.create();

       multimap.put("id1", new ExamProfile("examStudentId1"));

       multimap.put("id1", new ELearningProfile("userId1"));

       multimap.put("id2", new ExamProfile("examStudentId2"));

       multimap.put("id2", new ELearningProfile("userId2"));

       // print the data now.

       for (Map.Entry<String, Collection<Profile>> entry : multimap.entrySet()) {

           String key = entry.getKey();

           Collection<String> value =  multimap.get(key);

           System.out.println(key + ":" + value);

       }

   }

}

// assuming String as the studentId.

// assuming Profile as the interface. And Profile can multiple implementations that would be

// specific to student.

interface Profile {

}

class ExamProfile implements Profile {

   private String examStudentId;

   public ExamProfile(String examStudentId) {

       this.examStudentId = examStudentId;

   }

}

class ELearningProfile implements Profile {

   private String userId;

   public ELearningProfile(String userId) {

       this.userId = userId;

   }

}

This code is able to iterate through all entries in the Google Guava multimap and display all the students name in the associated students profile.

8 0
4 years ago
The top 3 most popular male names of 2017 are Oliver, Declan, and Henry according to babynames.
Naddik [55]

Answer:

#Set of three most popular names in 2007

male_names =  {'Oliver', 'Declan', 'Henry'}

#The male_names set is displayed to the user

print(male_names)

#The name to be removed is accepted from the user as a string

remove_name = str(input("Enter name to remove: "))

#The name to be added is accepted from the user as a string

add_name = str(input("Enter name to add: "))

#The remove method of a set is use to remove the received remove_name

male_names.remove(remove_name)

#The add method of a set is use to add the received add_name

male_names.add(add_name)

#The new set of male_names is displayed to the user

print(male_names)

Explanation:

4 0
3 years ago
Create a Word document or text file named Part3 that contains answers to the following:
Gnoma [55]

Answer:

11111

Explanation:

4 0
3 years ago
Other questions:
  • Alpha Technologies, a newly established company, wants to share information about its work with people all over the world. Which
    9·1 answer
  • Which partitioning method must be used for partitioning a 4-tb hard drive?
    6·1 answer
  • Suppose we are working with an error-correcting code that will allow all single-bit errors to be corrected for memory words of l
    5·1 answer
  • The process of auditing the source code for an application to verify that the proper security controls are present, that they wo
    14·1 answer
  • Https://www.bing.com/videos/search?q=dancing+aaron+smith+1+hour&amp;view=detail&amp;mid=C6C28AF3C0CEC1E4AEE3C6C28AF3C0CEC1E4AEE3
    14·1 answer
  • D) Software which is basically language translation software.​
    11·1 answer
  • How do you change your brainly lvl, it says I'm in collage but I'm in 8th grade :(
    10·2 answers
  • In what ways can information be slanted in a news report? List at least five ways.
    5·2 answers
  • Necesito ejemplos de actitud filosófica por favor
    8·1 answer
  • Write a C++ program to grade the answers to a true-false quiz given to students in a course. The quiz consists of 5 true-false q
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!