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
Discuss whether design considerations need to change for each kind of computer users. support your answer with an example.
vaieri [72.5K]
Each kind of computer users have different knowledge, needs and requirements. For example there is a difference between the computer knowledge of developers and users without <span>technical experience. Because of this, but also why they need and use computers, and what tools they need, design consideration need to change for each kind of computer users.</span>
<span>
</span>
8 0
3 years ago
In preparing a works cited list, you should
sergeinik [125]
In preparing a works cited list, you should mlways follow MLA style. MLA style is the proper way to cite references<span> </span>
7 0
3 years ago
Careful driving requires appropriate reaction time, both simple and complex. Braking and then shifting gears, followed by signal
QveST [7]
The correct answer is complex.
There are two types of reaction times when it comes to driving - simple and complex. Simple reaction time refers to your action after receiving some sort of a stimulus - when you see the red light, you are supposed to break. When it comes to complex reaction time, however, it has to do with your assessment of the situation, and realization what it is you have to do in order to avoid an accident, for example. 
4 0
3 years ago
Read 2 more answers
Advantages of using networks include all of these except for a. sharing data and info b. sharing software c. sharing passwords d
skelet666 [1.2K]

Answer:

C

Explanation:

Because they don't want you to share your password

7 0
3 years ago
You are designing software for elderly people. Which two features can you
romanna [79]

give instructions in both text and audio formats

7 0
3 years ago
Other questions:
  • Write a function M-file that takes as input two matrices A and B, and as output produces
    8·1 answer
  • The chip that controls the radio frequency waves within a device
    9·1 answer
  • Write a program that first reads in the name of an input file and then reads the input file using the file.readlines() method. T
    14·1 answer
  • The IBM nine-track tapes that became the industry standard for storage for three decades had several sizes , the most common bei
    13·1 answer
  • What are some of these new iPad extras? One is the iMarker. Crayola teamed up with another company to make it. It costs $29.99.
    8·1 answer
  • In our discussion of Computer Hardware, we talked about three essential hardware components that are there inside every computer
    14·1 answer
  • Which option is the default when creating appointments and meetings in a user’s own calendar as it relates to Free/Busy informat
    8·1 answer
  • Plz help Complete the sentence.
    11·2 answers
  • Rectangle perimeter is 72 .Find the new perimeter if length is doubled and breadth is tripled​
    7·1 answer
  • Write a function transpose(matrix) that returns the transpose of the input matrix, which is represented as a list of lists. Reca
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!