Introduction to Array || Java + DSA course || Blog 5
our phone starts to hang when we store too much . It means that our documents , videos , photos are taking too much space of the memory . The same way our code starts to hang when many variables are used differently as they are stored independently in the memory.
For a quick overview we will be learning;
- Array
- Ways to use array
- 2D array
- Take an array input/2D array input
An array is a collection of similar data elements stored at contiguous memory locations. It saves one type of arguments like int, float, string, etc.Instead of making many variables to save data, we save it together . This is called array.
It comes under user defined type. It store multiple items of the same type together.
If the size is considered as 3,then three arguments can be saved but the index starts from 0. it will go as array[0], array[1], array[2].
If you already know the argument and want to know make an array for after use, you can make it like:
If you want to know the number of arguments present in the array just write
Output will be 5.
The index of the last number will be marks.length - 1 since indexing starts from 0 while length from1.
To take input array:
2d Array
We have learnt matrix in our studying years. A matrix is a rectangular arrangement of numbers into rows and columns.
Here 3 is the row and 2 is the column
to save an int in
The output:
Here 100 is saved in array(1st row, 2nd column).
Lets take an 2d arrray as input.
Input:
2
3
12 13 14
15 16 17
Output:
12 13 14
15 16 17
___________________________________________________________________________________
VISIT: https://javaanddsa.blogspot.com/
DID YOU LIKE OUR BLOG?
PLEASE TELL US IN THE COMMENT SECTION
Great one
ReplyDeleteLoved it a lot
ReplyDelete