Java/C2/Introduction-to-Array/English
Title of script: Introduction to Arrays
Author: TalentSprint
Keywords: arrays, java, video tutorial
Visual Cue | Description |
Slide 1
Welcome |
Welcome to the spoken tutorial on Introduction to Arrays. |
Slide 2
Learning Outcomes |
In this tutorial, you will learn how
|
Slide 3
Tools Used |
For this tutorial we are using
|
Slide 4
Prerequisites |
For this tutorial, you should have knowledge of data types and for loop in Java.
|
Slide 5 and 6
Arrays
|
Arrays are a collection of data.
|
Minimize Slides and open Eclipse
Eclipse should contain the following code public class ArraysDemo{ public static void main(String[] args){ } } |
A class named ArraysDemo has already been created.
|
Inside main function, type
int rainfall[] = {25, 31, 29, 13, 27, 35, 12}; |
Inside main function, type
|
In the next line, type
System.out.println(rainfall[2]);
|
Next line, type
|
Save and run.
|
As we can see, the output is the third value, 29.
|
Change rainfall[2] to rainfall[0]
|
Change 2 to 0
|
Before the Syste... line, type
rainfall[0] = 11;
|
We shall change the value of the first item.
|
Now what if we only know the size of the array and do not know the values.
Let us see how to create such array. | |
Remove everything in main function and type
int squares[] = new int[10]; This statement creates an array of integers having 10 elements. The name of the array is squares. Now let us add some values.
| |
In the next line, type
squares[0] = 1; squares[1] = 4; squares[2] = 9; squares[3] = 16; |
Type
squares[1] = 4; squares[2] = 9; squares[3] = 16;
|
In the next line, type
System.out.println(squares[5]); |
We shall print the sixth value in the array.
|
Save and run. Point to output | We see that the value is zero. This is because when we create an array of integers, all the values are initialized to 0. Similarly an array of floats will have all its values initialized to 0.0.
|
After the squares[3] line, type
int n, x; for(x = 4; x < 10; x = x + 1){ n = x + 1; squares[x] = n * n } |
Type
for(x = 4; x < 10;x = x + 1){ n = x + 1; squares[x] = n * n }
|
Save and run. Point to output | As we can see, the sixth element now is the square of 6, which is 36.
|
Remove all the lines from
squares[0]... to squares[3]...
println(squares[2])
|
Remove the lines that set the values manually and change 4 to 0
|
This way, arrays can be created and used. | |
Minimize the Eclipse window and switch to slides.
Summary |
We have come to the end of this tutorial.
In this tutorial we have learnt how to use for loop in java. |
Slide 8Assignment | The assignment for this tutorial is,
|
Slide 9About the Spoken Tutorial Project
|
To know more about the Spoken Tutorial project, watch the video available at the following link. It summarises the project.If you do not have good bandwidth, you can download and watch it. |
Slide 10Spoken Tutorial WorkshopsThe Spoken Tutorial Project Team
|
The Spoken Tutorial Project Team. Conducts workshops using spoken tutorials and gives certificates for those who pass an online test. For more details, please write to contact AT spoken HYPHEN tutorial DOT org. |
Slide 11Acknowledgement
|
Spoken Tutorial Project is a part of the Talk to a Teacher project and is supported by the National Mission on Education through ICT, MHRD, Government of India. More information on this Mission is available at spoken HYPHEN tutorial DOT org SLASH NMEICT HYPHEN Intro |
Slide 12About the contributor
|
This script has been contributed by TalentSprint.
This is Prathamesh Salunke signing off. Thanks for joining.
|