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
What is an icon?
PtichkaEL [24]

Answer:

The answer to the given question is the option "4".

Explanation:

Icon is a small picture that helps the user to recognize a thing more easily. In computer science, an icon is a small picture or symbol that is used to provide a graphical description of the software program on a computer screen. In this question all other option is not correct that can be described as:  

The start menu is a button on the computer. In this button, there are many options or sub buttons. like, documents, pictures, help, and support, control panel, etc. So, it is not an icon.  

In the start menu, there is an option of the help and support so it is not an icon.

The background image is also known as wallpaper. So it is not an icon. That's why the answer to this question is the option "4".

8 0
4 years ago
Different the need for external or secondary memory​
alexira [117]

Answer:

Secondary storage is needed to keep programs and data long term. Secondary storage is non-volatile , long-term storage. Without secondary storage all programs and data would be lost the moment the computer is switched off.

External storage enables users to store data separately from a computer's main or primary storage and memory at a relatively low cost. It increases storage capacity without having to open up a system.

4 0
3 years ago
5. List three safety concerns when using hand<br> ertain safety<br> tools.
sveta [45]

Answer:

Inspect regularly. ...

Wear gloves. ...

Carry with care. ...

Don't pocket sharp objects. ...

Be aware of your surroundings. ...

Use the right tools.

6 0
3 years ago
Give reasons why you care for your sense organs​
Cerrena [4.2K]

HI!the resaon why should you care for you sense organs is that they help us to contact with our surroundings.

8 0
2 years ago
Read 2 more answers
The union of two bags is a new bag containing the combined contents of the original two bags. Design and specify a method union
irga5000 [103]

Omg does your fingers hurt?????! Are u okay?? Cause u typed a lot you could have just pictured it. Poor thing

3 0
3 years ago
Other questions:
  • What possible reason would explain why you are unable to connect to the intranet site on your computer’s web server, using a bro
    13·1 answer
  • _____ is when network managers deal with network breakdowns and immediate problems instead of performing tasks according to a we
    9·1 answer
  • To track website behavior data with google analytics, which steps will you need to complete?
    14·1 answer
  • A compressed format featuring small file size and good quality that is commonly used for online videos and music videos is BIN.
    8·1 answer
  • Let’s say you’re publishing a message with the Hootsuite Composer. The message contains a link to a landing page, and you want t
    9·1 answer
  • Business customers pay $0.006 per gallon for the first 8000 gallons. If the usage is more than 8000 gallons, the rate will be $0
    11·1 answer
  • Which of the following illustrations is depicted in the icon that's used to access Windows Help and Support files?
    13·1 answer
  • Managers can use __ software to discuss financial performance with the help of slides and charts
    11·1 answer
  • If you play video games, please answer these questions it’s for a survey for my game development class!!
    5·1 answer
  • Once the data center routes to the destination server that hosts the website, what's the next step in the Internet process?
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!