Arrays
Having to go in and create a whole bunch of variables can be a huge pain. Typing, typing, typing, typing!!! There is a different way to create multiple variables all at once and it is called creating an Array
Here is an example
int numbers[5];
the line above will create 5 slightly different variable that are an Integer. The five different variables created will be named
numbers[0]
numbers[1]
numbers[2]
numbers[3]
numbers[4]
All of these variables can manipulated in any fashion that we have done in previous lessons. They can be added, subtracted, multiplied, and divided. They can also be modulo'ed, assigned values, inputed into, and so on.
Here is an example
int numbers[5];
the line above will create 5 slightly different variable that are an Integer. The five different variables created will be named
numbers[0]
numbers[1]
numbers[2]
numbers[3]
numbers[4]
All of these variables can manipulated in any fashion that we have done in previous lessons. They can be added, subtracted, multiplied, and divided. They can also be modulo'ed, assigned values, inputed into, and so on.
Assignment
In this assignment you will begin to manipulate arrayed variables.
Build a program that:
1. Initializes a variable with the code below
2. Print out to the console all of the numbers in the loop that are even
Build a program that:
1. Initializes a variable with the code below
2. Print out to the console all of the numbers in the loop that are even
Initial code
var vector = new int [7] {4, 7, 2, 8, 1, 3, 0};
example results
4 2 8 0