Skip to content

Array Assignments#

Summing Up a Bunch of Numbers#

Assignment: Summing Up Numbers

Take these numbers: 40725, 53065, 98639, 27840, 58423, 71241, 27552, 70030, 52443, 50984, 19382, 32599, 73839, 79033, 71437, 80106, 25240, 34866, 10771, 31812 and put them into your own int array. Calculate the sum of all of these numbers. For that, please use any of the loops you already know.

Save the result to Sketch_10_Array_Summing_Up and make sure you commit and push it to gitlab.

Bonus: find the smallest and the largest numbers

Find and print the smallest and largest number of the list (assignment above!).

Reversing the Array#

Assignment: Reverse

Take this array and copy it to a new file:

String[] quotes = {
    "Just keep swimming.",
    "I'm the king of the world!",
    "You had me at hello.",
    "To infinity and beyond!",
    "Nobody puts Baby in a corner.",
    "Inconceivable!",
    "Roads? Where we're going we don't need roads.",
    "I'll be back.",
    "Toto, I've a feeling we're not in Kansas anymore."
};

You may realize that these are in the wrong order. Please reverse this array, or create a reversed copy in a new variable. For the purpose of this one exercise, the reverse()-function is not to be used and other "ready-made" functions are also not available to you. You should come up with your own way of reversing the lines.

The resulting array should start with "Toto ..." and end with "Just keep Swimming".

Save the result to Sketch_11_Array_Reverse and make sure you commit and push it to gitlab.

Last Five Keys#

Assignment: Last Five Keys

Store key-presses in an array. It is OK if only letters work for this particular example! Whenever a key is pressed, add the new letter at the end and display the result. It could look like this:

(minor explanation: the null null null null null in the beginning is my empty array. It is fine if this happens in your version, too. If you want to filter that out, that's of course also fine!)

Store this code in Sketch_12_Array_Last_Five_Keys and commit/push to gitlab.