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
Which is a monthly cost associated with renting a house?
Evgesh-ka [11]
The answer is a. utility bills
8 0
3 years ago
Read 2 more answers
Write a program whose inputs are three integers, and whose outputs are the largest of the three values and the smallest of the t
arlik [135]

Answer:

import java.util.*;

public class Main

{

public static void main(String[] args) {

    Scanner input = new Scanner(System.in);

    System.out.print("Enter the first number: ");

    int n1 = input.nextInt();

    System.out.print("Enter the second number: ");

    int n2 = input.nextInt();

    System.out.print("Enter the third number: ");

    int n3 = input.nextInt();

 System.out.println("largest: " + LargestNumber(n1, n2, n3));

 System.out.println("smallest: " + SmallestNumber(n1, n2, n3));

}

public static int LargestNumber(int num1, int num2, int num3){

    int largestNum = 0;

    if(num1>=num2 && num1>=num3)

        largestNum = num1;

    else if(num2>=num1 && num2>=num3)

        largestNum = num2;

    else if(num3>=num1 && num3>=num2)

        largestNum = num3;

       

    return largestNum;

}

public static int SmallestNumber(int num1, int num2, int num3){

    int smallestNum = 0;

    if(num1<=num2 && num1<=num3)

        smallestNum = num1;

    else if(num2<=num1 && num2<=num3)

        smallestNum = num2;

    else if(num3<=num1 && num3<=num2)

        smallestNum = num3;

       

    return smallestNum;

}

}

Explanation:

Create function called LargestNumber that takes three parameters, num1, num2, num3. Find the largest number using if else structure among them and return it. For example, if num1 is both greater than or equal to num2 and num3, then it is the largest one.

Create function called SmallestNumber that takes three parameters, num1, num2, num3. Find the smallest number using if else structure among them and return it. For example, if num1 is both smaller than or equal to num2 and num3, then it is the smallest one.

Inside the main, ask the user for the inputs. Call the functions and print the largest and smallest.

8 0
3 years ago
A technician wants to update the organization's disaster recovery plans. Which of the following will allow network devices to be
Illusion [34]

Answer:B) Archives/backups

Explanation: Archive is the group of records of data that are saved for the future use.These are the historic data that is not currently used in the actual location .

Backup is the the the copy of the group of data that is not in the original form to be used in future. Thus the correct option is option(B).

Updating of the plans by the technician cannot be done through other given options because they don't hold the historic records of the data for the renewing of the plans.

6 0
3 years ago
You want some points? whoever answers first gets 48 points. no cap. better be quick.
LekaFEV [45]

Answer:

4

Explanation:

5 0
3 years ago
Read 2 more answers
Consider the following statements: Statement A: In Duplex transmission, either node can transmit while the other node can receiv
sergij07 [2.7K]

Answer:

<u>d. Statement A is true and Statement B is false</u>

Explanation:

Indeed, when using duplex transmission either node can transmit while the other node can receive data from the network. Also, in half-duplex transmission, both the nodes can transmit as well as receive data.

However, in half-duplex transmission, the nodes <em>cannot </em>transmit and receive data at the same time. Hence, this makes Statement B false, while Statement A is true.

4 0
3 years ago
Other questions:
  • What type of change can AutoCorrect option make to a word?
    10·2 answers
  • Write a program to calculate how much to tip a waiter person based on the quality of service. The script file should ask for the
    12·1 answer
  • . The toasting cycle of an automatic toaster is started by A. pushing the bread rack down. B. pushing the start button. C. turni
    14·2 answers
  • What are the three default security levels within software restriction policies?
    12·1 answer
  • __________ use a challenge response mechanism in which a server challenges a user with a number, which a user must then enter in
    5·1 answer
  • print out the last even number from an array of integers, if there is no even number, then print out a sentence indicating so.
    5·1 answer
  • What is the smallest amount of information called?
    13·2 answers
  • Give one example of where augmented reality is used​
    11·2 answers
  • nts/viewer/classes/289ef1a5d7c341c284010 Select the compound inequality shown on the graph. 5 4 3 2 1 0 1 2 를 4​
    6·1 answer
  • In a selection, the else clause executes ______________. a. always b. when the tested condition is false c. when the tested cond
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!