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

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 18:00, ladyree8721
Which of the following physical laws can make the flow of water seem more realistic? a. motion b. gravity c. fluid dynamics d. thermodynamics
Answers: 2
image
Computers and Technology, 24.06.2019 08:30, daskatingpanda
Formatting rows and columns is similar to cell formatting. in an openoffice calc spreadsheet, you can format data entered into rows and columns with the of the rows and columns options. you can insert rows and columns into, or delete rows and columns from, a spreadsheet. use the insert or delete rows and columns option on the insert tab. alternatively, select the row or column where you want new rows or columns to appear, right-click, and select insert only row or only column options. you can hide or show rows and columns in a spreadsheet. use the hide or show option on the format tab. for example, to hide a row, first select the row, then choose the insert tab, then select the row option, and then select hide. alternatively, you can select the row or columns, right-click, and select the hide or show option. you can adjust the height of rows and width of columns. select row and then select the height option on the format tab. similarly, select column, then select the width option on the format tab. alternatively, you can hold the mouse on the row and column divider, and drag the double arrow to the position. you can also use the autofit option on the table tab to resize rows and columns.
Answers: 1
image
Computers and Technology, 25.06.2019 06:20, joe7977
If you want to change the speed of a layer's horizontal scrolling, what should you change? a. the x coefficient b. the y coefficient c. the virtual width d. the order of the game's layers select the best answer from the choices provided
Answers: 2
image
Computers and Technology, 25.06.2019 16:00, Onlytrillest
|the entire hostname has a maximum of
Answers: 1
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 in other subjects:

Konu
History, 24.08.2019 22:30