subject

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
}

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 12:00
Which of the following “invisible” marks represents an inserted tab?
Answers: 1
question
Computers and Technology, 23.06.2019 13:00
Donnie does not have powerpoint. which method would be best for elana to save and share her presentation as is? a pdf a doc an rtf a ppt
Answers: 3
question
Computers and Technology, 24.06.2019 01:00
What shows the web address of the page that is currently displayed in the workspace? status window toolbar location bar internet box
Answers: 1
question
Computers and Technology, 24.06.2019 08:50
Write a program that will compute the volume of ice cream served in a cone. as you can see in the diagram below, the ice cream is served as a hemisphere of frozen deliciousness on top of a cone, which is also packed with frozen deliciousness. thus, the total volume of ice cream sold is the volume of the hemisphere plus the volume of the cone. the example shows an ice cream cone in which the hemisphere and cone have a radius of 10 inches and the cone has a height of 15 inches. your program must instead prompt for these two values, which are taken from the keyboard as integers: • the hemisphere/cone radius in inches, and
Answers: 3
You know the right answer?
Write a static method named stretch that accepts an array of integers as a parameter and returns a n...
Questions
question
Mathematics, 16.11.2020 06:10
question
Mathematics, 16.11.2020 06:10
question
Mathematics, 16.11.2020 06:20
question
Mathematics, 16.11.2020 06:20
question
Mathematics, 16.11.2020 06:20
question
History, 16.11.2020 06:20
Questions on the website: 13722363