Computers and Technology, 20.02.2020 19:21 amaliathornton22
Write a static method named stretch that accepts an array of integers as a parameter and returns a new array that is twice as large as the original, replacing every integer from the original array with a pair of integers, each half the original. If a number in the original array is odd, then the first number in the new pair should be one higher than the second so that the sum equals the original number.
For example, if a variable named list refers to an array storing the values {18, 7, 4, 24, 11}, the call of stretch(list) should return a new array containing {9, 9, 4, 3, 2, 2, 12, 12, 6, 5}. (The number 18 is stretched into the pair 9, 9, the number 7 is stretched into 4, 3, the number 4 is stretched into 2, 2, the number 24 is stretched into 12, 12 and the number 11 is stretched into 6, 5.)
Check the code with the following class:
import java. util. Arrays;
public class Stretching
{
public static void main(String[] args)
{
int[] list = {18, 7, 4, 14, 11};
int[] list2 = stretch(list);
System. out. println(Arrays. toString(list));
// the above prints [18, 7, 4, 14, 11]
System. out. println(Arrays. toString(list2));
// the above prints [9, 9, 4, 3, 2, 2, 7, 7, 6, 5]
}
// your code goes here
}
Answers: 1
Computers and Technology, 23.06.2019 01:30
For a typical middle-income family, what is the estimated cost of raising a child to the age of 18? $145,500 $245,340 $304,340 $455,500
Answers: 2
Computers and Technology, 23.06.2019 08:30
When you interpret the behavior of others according to your experiences and understanding of the world your evaluation is
Answers: 1
Computers and Technology, 23.06.2019 14:00
Select the correct answer. andre was recently hired by an organization to check for system vulnerabilities. he is supposed to exploit these vulnerabilities and create a report on the extent of damage to which the system was susceptible. what position does andre hold in this organization? a. information security analyst b. information assurance manager c. penetration tester d. network security engineer e. chief information security officer
Answers: 2
Computers and Technology, 24.06.2019 02:30
Which option completes the explanation for conflict of interest in an organization
Answers: 1
Write a static method named stretch that accepts an array of integers as a parameter and returns a n...
Chemistry, 03.06.2021 16:40
Mathematics, 03.06.2021 16:40
Mathematics, 03.06.2021 16:40
History, 03.06.2021 16:40
Chemistry, 03.06.2021 16:40
Geography, 03.06.2021 16:40
Mathematics, 03.06.2021 16:40
Mathematics, 03.06.2021 16:40
Mathematics, 03.06.2021 16:40
English, 03.06.2021 16:40
Chemistry, 03.06.2021 16:40
Mathematics, 03.06.2021 16:40