Question: Valentines Day Question(JAVA) Suppose you had a list with 30 valentines and you stored their names in an array (you hopeless romantic). Then if you

Valentines Day Question(JAVA)

Suppose you had a list with 30 valentines and you stored their names in an array (you hopeless romantic). Then if you had 5 people ask to be your valentine, you would need to make a new array of size 35 (30 + 5) and copy over the original valentines before being able to add the new valentines to the array. This question uses the same logic.

Write a program that has a method called doubleSize. The method takes in an array of integers called values. The method will create a new array of integers that will be double (two times) the size of the passed in array. It will copy all the integers contained in values to the new array and return the new array.

In the main method:

  • Use a Scanner object to read in one int (n) that represents the size of an array of integers. Create an array of integers that uses this first number as the size.
  • You will then read in (n) ints all on the same line and store them in the array.
  • Call the method doubleSize and pass in the array of integers. This will return a new array with copied values.
  • Print the elements of the new array in the main method.

The method header looks as follows:

public static int [] doubleSize (int[] values)

You must use a method.

Input

In integer (n), followed by a list of n integers.

Example Input: 5 12 34 12 9 -7

Output

A single double representing the smallest number.

Example Output: 12 34 12 9 -7 0 0 0 0 0

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!