Search Header Logo
init array lesson

init array lesson

Assessment

Presentation

Computers

9th Grade

Practice Problem

Medium

Created by

Daniel Latusek

Used 3+ times

FREE Resource

15 Slides • 9 Questions

1

media

Init array

2

media

Init = initialize

Init is short or initialize, which means to set the value at the
start of the program

When I initialize the program I am starting the program

When I initialize java it runs commands in the main method

When I initialize a variable I am telling the variable what it's
value is

3

Multiple Choice

What does it mean to initialize?

1

To end

2

To start

3

To play games on your phone

4

media

declaring a varaible

When I declare a variable I am naming a variable

int age = 34;

String name = "Mr. Latusek";

boolean hasCoffee = true;

I declare what the variable type is(int, string, boolean, etc)

I give the variable a name (age, name, hasCoffee)

I initialize the variable, or give it a starting value (34,"Mr. Latusek", true)

5

Multiple Choice

What does it mean to declare a variable

1

To change it's value

2

to delete a variable

3

To create and name a variable

6

media

Declaring a variable that is not initialized

I can create a variable without giving it a value.

int age;

String name;

boolean hasCoffee;

These variables are given a default value of void. This means that they
are empty.

Watch out! Void is not an integer, nor String, nor boolean. You cannot
compare void with these variables

7

Multiple Choice

What is the value of int age; before it is initialized

1

32

2

0

3

void

8

media

initializing after the declaration

We can declare a variable without giving it a value and then
give it a value later;

int age;

age = 34;

age was void until I said it was 34.

This is often done when the variable will be given by a user

9

Multiple Choice

What is the value of int age; after the statement age = 32;?

1

32

2

0

3

void

10

media

Array

Arrays are an ordered collection of values and behave much
like any other variable.

I declare the variable type (int, String, Boolean), give it a name,
(array, name, hasCoffee) and then initialize the value;

int array[];

array = new int[10];

But this looks different.

11

Multiple Choice

What is an array?

1

the name of a variable

2

a collection of variables of the same type

3

It's like an x-ray, but using a beams

12

media
media

Setting values to an array

So we looked at creating an array

we looked at initializing an array

but what if I create an array and give it values?

I create an empty array, tell it how big it is, then
just like an integer I tell it what the values are
for that index

13

media

Array

int array[];

The square braces after array tell me that it will be an array,
which will hold a number of integers (we declared array as
int)

right now it is not given a value to java says it is set to void,
which has no value;

14

Multiple Choice

What part of int array[]; tells me it is an array?

1

int

2

array

3

[]

15

media

Array

int array[];

array = new int[10];

we then declare array is a new integer array with 10 places.
This means that I have a thing called array that holds 10
numbers. Right now they are all set to 0.

[0,0,0,0,0,0,0,0,0,0]

16

Multiple Choice

What are the values of array[] = new int[10];

1

10

2

0

3

void

17

media

Array

[0,0,0,0,0,0,0,0,0,0]

We called array an ordered set, because each number has a
placeholder number attached to it.

the first number is 0

the second number is 0

the third number is 0…

18

Multiple Choice

What is the 4th value of array = new int[10];

1

10

2

4

3

0

4

void

19

media
media

InitArray

Our class name InitArray is short for initializing array

Initializing means to set to the value or put in the condition
appropriate to the start of an operation

more simply it means to set the start value

But we didn't set any values to begin with

all the values were set to 0

20

media

InitArrayTwo

int array[] = {32,27,64,18,95,14,90,70,60,37}; // declare array
named array

System.out.printf("%s%8s\n", "Index", "Value");

for (int counter = 0; counter <array.length; counter++){

System.out.printf("%5d%8d\n", counter, array[counter]);

Here we give our array values when we declare it

array[0] = 32, array[1] = 27, array[2] = 64

21

media

22

Multiple Choice

What is the 4th value of int array[] = {32,27,64,18,95,14,90,70,60,37};

1

0

2

4

3

32

4

18

23

media

InitArrayThree

final int ARRAY_LENGTH = 10;

int array[] = new int[ARRAY_LENGTH]; // declare array named array

for(int counter =0;counter<array.length;counter++){

array[counter] = 2+2*counter;}

System.out.printf("%s%8s\n", "Index", "Value"); // column headings

for (int counter = 0; counter <array.length; counter++){

System.out.printf("%5d%8d\n", counter, array[counter]); } // end for

24

media
media

Init array

Show answer

Auto Play

Slide 1 / 24

SLIDE