Creating Arrays Tutorial

From Progzoo
Jump to: navigation, search

You can create an array with the phrase

int [] a = new int[10];

In these example you create a new array and return that array.

Double Everything

Return the array with every element doubled.

For the array [2, 7, 5, 3] you should return [4, 14, 10, 6]:


[Font] [Default] [Show] [Resize] [History] [Profile]

Shrink the array

Return a copy of the array with the last element missing

For the array [2, 7, 5, 3] you should return [2, 7, 5]:


[Font] [Default] [Show] [Resize] [History] [Profile]

Two copies the Array

Return an array twice the size with every element copied.

For the array [2, 7, 5, 3] you should return [2, 7, 5, 3, 2, 7, 5, 3]:


[Font] [Default] [Show] [Resize] [History] [Profile]

Duplicate each element

Return an array twice the size with every element copied.

For the array [2, 7, 5, 3] you should return [2, 2, 7, 7, 5, 5, 3, 3]:


[Font] [Default] [Show] [Resize] [History] [Profile]

Reverse the array

Return the array reversed

For the array [2, 7, 5, 3] you should return [3, 5, 7, 2]:


[Font] [Default] [Show] [Resize] [History] [Profile]