Before we start, did you try solving the workbook yourself?
If not, please click the link in the resources folder and follow the instructions for this workbook.
Welcome to Workbook 6.13.
Task one is to create a 2D array of double values that can hold three rows and five elements per row.
So we will create a 2D array that can store elements of type double.
I will call it prices.
We'll set it equal to a new double array that can store three rows and each row is going to hold five
elements.
All right.
Task number two is to populate your 2D array with values from the following table.
And for the sake of exercise, we do it the long way where we index elements one by one.
So here we're going to say prices.
First, we will focus on elements inside row zero.
The first element inside row zero is 1299.
The second element inside RO zero is 899.
The third element that rose zero is 999.
And I'll let you finish the rest.
All right.
I hope you got something like this.
And if you missed a number or two, it doesn't really matter.
It doesn't have to be exact.
Maybe I missed a number to who knows?
But we've got three rows and five elements per row.
All right.
And now what we're going to do is print the prices of each row using this format.
So let's copy this over.
So here what they're doing is they're printing every single element in row zero.
They printed the element at index zero and Dux one.
Let's continue this.
Print the element of index to over zero.
The element at index three of row zero and the element at index for.
Okay.
Now we can literally just copy and paste this here.
We can print every single element inside of row one.
And here every element inside of row to.
This is the result that we should expect.
So let's go ahead, put a breakpoint to right here and debug the runtime.
So this is going to do is create a two rd array that has three rows and five elements per row.
All right, There is our two RD array.
Three rows and five elements per row.
Here we are, fixed on row zero, and we're updating the first element to a row 0 to 1299.
The second element to a row 0 to 899.
The element at index two of row zero ten 999.
The element at index 3 to 1049.
The element at index 4 to 1199.
This one is also going to update five elements, but this time a row one.
And this will update all five elements inside of row to the element that index zero index one, two,
three, four.
Here.
We're printing every single element inside of Rose Zero.
Here we're printing every single element inside of row one.
Here we print every element inside of row two.
And this is looking good.
All right.
Task number four is to define the array in a single line.
So instead of this atrocity, we can just say.
Double prices is equal to three rows.
And you'll notice each row is like its own array that has five elements.
And now you know what?
Although this wasn't in our workbook, let's do it anyway.
We'll create a for loop where I start to zero.
The for loop is going to keep running so long as I is smaller than three.
So until it reaches two plus plus.
And you'll notice that the only value that's changing is this one.
So we can replace this with I.
Och, this wasn't in your workbook, so don't worry if you didn't do this, but I just want to do it
anyway because I think it would be fun to visualize.
So here our for loop starts with I equaling zero, which means we're going to be indexing every single
element inside of row zero.
Now I equals one, which means now we are printing every single element inside of row one.
Now I equals two, which means we are printing every single element inside of row to.
All right.
IPOs plus increases 2 to 3.
Three is not smaller than three.
So our loop breaks.
And that's it.
I hope you enjoyed this breakpoint session.