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
The IntList class contains code for an integer list class. Study it; notice that the only things you can do are: create a list o
torisob [31]

Explanation:

public class Int_List

{

protected int[] list;

protected int numEle = 0;

 

public Int_List( int size )

{

list = new int[size];

public void add( int value )

{

if ( numEle == list.length )

{

System.out.println( "List is full" );

}

else

{

list[numEle] = value;

numEle++;

}

}

public String toString()

{

String returnStr = "";

for ( int x = 0; x < numEle; x++ )

{

returnStr += x + ": " + list[x] + "\n";

}

return returnStr;

}

}

public class Run_List_Test

{

public static void main( String[] args )

{

 

Int_List myList = new Int_List( 7 );

myList.add( 102 );

myList.add( 51 );

myList.add( 202 );

myList.add( 27 );

System.out.println( myList );

}

}

Note: Use appropriate keyword when you override "tostring" method

8 0
2 years ago
Which statement best describes network security
Andreyy89
<span>B.network security means all personal information is kept safe the network is not compromised and only authorized users had access 

Im pretty sure they ment has instead of had</span><span />
3 0
2 years ago
Read 2 more answers
What is the purpose of a report?
Tanzania [10]
C to organize data in a table
4 0
3 years ago
When widgets, or portable chunks of code, are embedded on html pages and thereby help increase the functionality of those pages,
Anna11 [10]
<span>When widgets, or portable chunks of code, are embedded on html pages and thereby help increase the functionality of those pages, consumers embrace one of the greatest virtues of social media known as Collaboration.</span>
5 0
3 years ago
What is the name of small programs stored on the hard drive that tell the computer how to communicate with a specific hardware d
Katena32 [7]
Small programs stored on the harddrive that provide basic functionality for he devices listed would be called Hardware Drivers.
I hope this helps!
5 0
3 years ago
Other questions:
  • 1. The future of 2D animation does not include hand-drawing. (1 point)
    13·1 answer
  • • What is the difference between primary storage, secondary storage, and off-line storage
    10·1 answer
  • Which device can be installed on the edge of your network to allow multiple remote users to connect securely to your internal en
    9·1 answer
  • Write a program that reads students’ names followed by their test scores. The program should output each student’s name followed
    13·1 answer
  • Which is a circuit board located behind an LCD screen on a laptop?
    7·1 answer
  • Which are advantages of using a server operating system?
    12·1 answer
  • Assuming that we only support BEQ and ADD instructions, discuss how changes in the given latency of this resource affect the cyc
    7·1 answer
  • Respond to the following in a paragraph of no less than 125 words. Describe the steps to active listening.
    7·2 answers
  • What do you suggest for Father's Day?​
    7·1 answer
  • Remember not to use tools that are ________ in any way.
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!