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
nikklg [1K]
3 years ago
10

The elements of an integer-valued array can be initialized so that a[i] == i in a recursive fashion as follows: An array of size

0 is already initialized; Otherwise set the last element of the array to n-1 (where n is the number of elements in the array, for example, an array of size 3 will have its last element -- index 2-- set to 2; and initialize the portion of the array consisting of the first n-1 elements (i.e., the other elements of the array) Write a void method named init that accepts an integer array, and the number of elements in the array and recursively initializes the array so that a[i] == i.
Computers and Technology
1 answer:
blondinia [14]3 years ago
4 0

Answer:

public static void init(int[] arr, int n) {

    if (n==0)

        arr[0] = 0;

    else {

        arr[n-1] = n - 1;

        init(arr, n-1);

    }

}

Explanation:

Create a method called init that takes two parameters, an array and the number of elements in the array

When n reaches 0, set the first element to 0 (This is a base for our recursive method)

Otherwise, set the element in index i to i

Call the init inside the init, this is the recursion part, with same array but decrease the number of elements by 1 (We decrease the number of element by 1 in each time so that it goes through all the elements in the array)

You might be interested in
Write the definition of a function named printpoweroftwostars that receives a non-negative integer n and prints a line consistin
Aleksandr-060686 [28]
To accomplish this without using a loop,
we can use math on a string.

Example:
print("apple" * 8)

Output:
appleappleappleappleappleappleappleapple

In this example,
the multiplication by 8 actually creates 8 copies of the string.

So that's the type of logic we want to apply to our problem.

<span>def powersOfTwo(number):
if number >= 0:
return print("*" * 2**number)
else:
<span>return

Hmm I can't make indentations in this box,
so it's doesn't format correctly.
Hopefully you get the idea though.

We're taking the string containing an asterisk and copying it 2^(number) times.

Beyond that you will need to call the function below.
Test it with some different values.

powersOfTwo(4) should print 2^4 asterisks: ****************</span></span>
4 0
4 years ago
Write a spellcheck() method that takes a word as a parameter and returns true if it is in the dictionary array. It should return
makkiz [27]

Answer:

See attached file for detailed code.

Explanation:

See attached file.

Download txt
6 0
3 years ago
What command is used to request the name and address information from a dns server?
topjm [15]
Nslookup is deprecated in favor of dig
7 0
4 years ago
Properties of variable in QBASIC​
Arlecino [84]

Explanation:

assume numeric value and is represented by an alphabet or an alphabet followed by another alphabet or digit. ...

String variable : A string variable is represented by an alphabet followed by dollar ()sign.

4 0
3 years ago
Please help it's my last question
Yuki888 [10]

Explanation:

here is your answer.. of. different between client / server architecture and peer to peer architecture of the network.

6 0
3 years ago
Read 2 more answers
Other questions:
  • Which change signaled a musical progression toward rock and roll?
    14·1 answer
  • Which of these tasks can be accomplished when the drop-down menu of the Bullets icon is clicked?
    14·1 answer
  • Fazer um programa em C++ que contenha 3 funções sendo:
    11·1 answer
  • To what type of user does he most likely have access? Jae is using a computer at the public library to do research she's able to
    9·1 answer
  • 1) List at least five smaller behaviors you could break the complex behavior "brushing my teeth" into.
    14·2 answers
  • What is the awnser ?
    11·1 answer
  • Explain why interrupt times and dispatch delays must be limited to a hard real-time system?
    8·1 answer
  • I can’t get answers because the ads won’t load help me
    12·1 answer
  • What is the relationship between an object and a class? A. An object is an instance of a class. B. A class is an instance of an
    5·1 answer
  • Hello :) new day <br> which one would u pick?<br> 1. chips 2. Gacha life 3. chocolate?<br><br> hehe
    15·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!