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
Nina [5.8K]
3 years ago
11

Write a recursive, int-valued method, len, that accepts a string and returns the number of characters in the string.

Computers and Technology
1 answer:
marin [14]3 years ago
7 0

Answer:

See Explanation Below

Explanation:

We name our recursive function to be "len" without the quotes

Also, the string whose length is to be calculated is named as StringCalc

Please note that only the function is written; the main method is omitted and it's written in Java Programming Language

The recursive function is as follows:

public int len(String StringCalc){

// Check if StringCalc is an empty string

if (StringCalc.isEmpty())

{

return 0;

}

// If otherwise; i.e. if StringCalc is not empty

else{

// Calculate length of string

int lengths = StringCalc.length();

// Return the length of string from the second character till the last

return (1 + len(StringCalc.substring(1, lengths)));

}

}

// End

The first line of the code declares the recursive function

public int len(String StringCalc)

The next line checks if the input string is empty

if (StringCalc.isEmpty())

This can also be written as

if(StringCalc == "")

If the above is true, the recursive returns the value of 0

Else; (i.e. if it's not an empty string), it does the following

It calculates the length of the string as follows

int lengths = StringCalc.length();

The length of the string is saved in variable "lengths"

Then the length of the string starting from the second character is calculated; since the index string is taken as 0, the recursive consider character at index 1 till the last index.

You might be interested in
Question 1: An acronym is a word formed by taking the first letters of the words in a phrase and making a word from them. For ex
jeka94

Answer:

See explaination

Explanation:

def main():

phrase = input('please enter a phrase: ')

acronym = ''

for word in phrase.split():

acronym += word[0].upper()

print('Acronym for ' + phrase + ' is ' + acronym)

main()

See attachment for the output

5 0
4 years ago
When entering a formula into a cell, you begin with are calculations a spreadsheet program applies to data. are preset calculati
Ugo [173]

Answer:

When entering a formula into a cell, you begin with  an equal sign

Functions and formulas are calculations a spreadsheet program applies to data.

Functions are preset calculations within spreadsheet software.

Formulas are user-entered calculations that may contain cell references, numerical values, and preset calculations.

Explanation:

I did the assignment on Edge 2020.

7 0
3 years ago
Which of the following is not an acceptable way to code a nested structure? Select one: a. nest a for loop inside a while loop b
kirill115 [55]

Answer:

nest an else clause within an elif clause

Explanation:

in python Programming, we cannot nest an else clause within an elif clause. elif is actually else if condition. we cannot nest another else with in elif clause.

8 0
3 years ago
Which three items might appear on the project plan when discussing an upcoming website with a design team? (Choose three)
stepladder [879]
Planning and analysis, due dates and payment details .
5 0
3 years ago
During the processing stage what does the computer do
Ann [662]
<span>The finished product is "output." In the electronic computer, data are the raw material or input to the computer.</span>
5 0
4 years ago
Other questions:
  • Alice has to move around a lot to fetch objects at her workstation. Which ergonomic principle should Alice follow to prevent str
    8·2 answers
  • What output is produced by the following program segment? Why? (Recall that name.charAt(i) is the i-th character in the string,
    11·1 answer
  • Public static void prefixmerge(customer[] list1, customer[] list2, customer[] result {
    6·1 answer
  • Maggie is preparing a document.she wants to open the help menu to sort out a formatting problem.which key should she press to op
    15·2 answers
  • A user is troubleshooting a mobile device app that is displaying errors and has contacted the app manufacturer’s technical suppo
    14·1 answer
  • Sam plans to use this image in artwork for a brochure about airplanes. Which principles of page layout is Sam planning to use in
    11·1 answer
  • Write a program that asks a user to enter a date in month day year format (for example 10 12 2016) and displays the day of the w
    5·1 answer
  • Any Danganronpa fans around here? I'm bored.
    13·2 answers
  • Cuál es el objetivo principal de una clave primaria?
    14·1 answer
  • It is used to loosen or tighten slotted screws. * 1 point A. Hex Driver B. Torx Screwdriver C. Philips Head Screwdriver D. Flat
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!