Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Manga Guide To Databases

Authors: Mana Takahashi, Shoko Azuma, Co Ltd Trend

1st Edition

1593271905, 978-1593271909

More Books

Students also viewed these Databases questions

Question

What are the different techniques used in decision making?

Answered: 1 week ago