1 00:00:00,700 --> 00:00:04,390 Before we start, did you try solving the workbook yourself? 2 00:00:04,420 --> 00:00:10,180 If not, please click the link in the resources folder and follow the instructions for this workbook. 3 00:00:10,870 --> 00:00:12,790 Welcome to Workbook 6.13. 4 00:00:12,790 --> 00:00:18,130 Task one is to create a 2D array of double values that can hold three rows and five elements per row. 5 00:00:18,130 --> 00:00:22,690 So we will create a 2D array that can store elements of type double. 6 00:00:22,690 --> 00:00:24,250 I will call it prices. 7 00:00:24,250 --> 00:00:33,040 We'll set it equal to a new double array that can store three rows and each row is going to hold five 8 00:00:33,040 --> 00:00:33,970 elements. 9 00:00:34,300 --> 00:00:34,870 All right. 10 00:00:34,900 --> 00:00:39,700 Task number two is to populate your 2D array with values from the following table. 11 00:00:40,600 --> 00:00:45,630 And for the sake of exercise, we do it the long way where we index elements one by one. 12 00:00:45,640 --> 00:00:48,380 So here we're going to say prices. 13 00:00:48,400 --> 00:00:51,970 First, we will focus on elements inside row zero. 14 00:00:52,000 --> 00:00:55,840 The first element inside row zero is 1299. 15 00:00:58,890 --> 00:01:02,580 The second element inside RO zero is 899. 16 00:01:06,950 --> 00:01:10,280 The third element that rose zero is 999. 17 00:01:11,970 --> 00:01:13,950 And I'll let you finish the rest. 18 00:01:19,200 --> 00:01:19,530 All right. 19 00:01:19,530 --> 00:01:21,210 I hope you got something like this. 20 00:01:21,210 --> 00:01:24,840 And if you missed a number or two, it doesn't really matter. 21 00:01:24,850 --> 00:01:26,430 It doesn't have to be exact. 22 00:01:26,460 --> 00:01:28,880 Maybe I missed a number to who knows? 23 00:01:28,890 --> 00:01:33,690 But we've got three rows and five elements per row. 24 00:01:33,720 --> 00:01:34,770 All right. 25 00:01:34,770 --> 00:01:40,370 And now what we're going to do is print the prices of each row using this format. 26 00:01:40,380 --> 00:01:42,120 So let's copy this over. 27 00:01:44,310 --> 00:01:48,750 So here what they're doing is they're printing every single element in row zero. 28 00:01:48,780 --> 00:01:51,980 They printed the element at index zero and Dux one. 29 00:01:51,990 --> 00:01:53,820 Let's continue this. 30 00:01:55,840 --> 00:01:58,930 Print the element of index to over zero. 31 00:02:00,700 --> 00:02:06,190 The element at index three of row zero and the element at index for. 32 00:02:09,940 --> 00:02:10,320 Okay. 33 00:02:10,330 --> 00:02:14,110 Now we can literally just copy and paste this here. 34 00:02:14,110 --> 00:02:17,350 We can print every single element inside of row one. 35 00:02:20,730 --> 00:02:23,940 And here every element inside of row to. 36 00:02:28,360 --> 00:02:30,180 This is the result that we should expect. 37 00:02:30,190 --> 00:02:35,440 So let's go ahead, put a breakpoint to right here and debug the runtime. 38 00:02:36,580 --> 00:02:41,950 So this is going to do is create a two rd array that has three rows and five elements per row. 39 00:02:42,710 --> 00:02:44,930 All right, There is our two RD array. 40 00:02:44,960 --> 00:02:48,020 Three rows and five elements per row. 41 00:02:48,200 --> 00:02:54,800 Here we are, fixed on row zero, and we're updating the first element to a row 0 to 1299. 42 00:02:54,800 --> 00:02:58,250 The second element to a row 0 to 899. 43 00:02:58,280 --> 00:03:01,820 The element at index two of row zero ten 999. 44 00:03:01,820 --> 00:03:04,460 The element at index 3 to 1049. 45 00:03:04,460 --> 00:03:07,380 The element at index 4 to 1199. 46 00:03:07,400 --> 00:03:11,900 This one is also going to update five elements, but this time a row one. 47 00:03:13,260 --> 00:03:19,950 And this will update all five elements inside of row to the element that index zero index one, two, 48 00:03:19,950 --> 00:03:20,940 three, four. 49 00:03:22,340 --> 00:03:22,700 Here. 50 00:03:22,700 --> 00:03:26,090 We're printing every single element inside of Rose Zero. 51 00:03:26,120 --> 00:03:29,510 Here we're printing every single element inside of row one. 52 00:03:29,540 --> 00:03:33,340 Here we print every element inside of row two. 53 00:03:33,350 --> 00:03:35,870 And this is looking good. 54 00:03:36,440 --> 00:03:37,220 All right. 55 00:03:37,250 --> 00:03:40,700 Task number four is to define the array in a single line. 56 00:03:40,700 --> 00:03:45,440 So instead of this atrocity, we can just say. 57 00:03:46,790 --> 00:03:50,180 Double prices is equal to three rows. 58 00:03:50,570 --> 00:03:55,160 And you'll notice each row is like its own array that has five elements. 59 00:03:56,150 --> 00:03:57,670 And now you know what? 60 00:03:57,680 --> 00:04:00,680 Although this wasn't in our workbook, let's do it anyway. 61 00:04:01,610 --> 00:04:04,910 We'll create a for loop where I start to zero. 62 00:04:04,940 --> 00:04:09,470 The for loop is going to keep running so long as I is smaller than three. 63 00:04:09,470 --> 00:04:12,350 So until it reaches two plus plus. 64 00:04:14,500 --> 00:04:18,760 And you'll notice that the only value that's changing is this one. 65 00:04:18,760 --> 00:04:21,040 So we can replace this with I. 66 00:04:28,100 --> 00:04:32,840 Och, this wasn't in your workbook, so don't worry if you didn't do this, but I just want to do it 67 00:04:32,840 --> 00:04:35,480 anyway because I think it would be fun to visualize. 68 00:04:35,600 --> 00:04:43,430 So here our for loop starts with I equaling zero, which means we're going to be indexing every single 69 00:04:43,430 --> 00:04:47,300 element inside of row zero. 70 00:04:50,940 --> 00:04:57,900 Now I equals one, which means now we are printing every single element inside of row one. 71 00:05:00,320 --> 00:05:07,040 Now I equals two, which means we are printing every single element inside of row to. 72 00:05:09,190 --> 00:05:09,820 All right. 73 00:05:09,820 --> 00:05:12,430 IPOs plus increases 2 to 3. 74 00:05:12,430 --> 00:05:14,140 Three is not smaller than three. 75 00:05:14,140 --> 00:05:15,640 So our loop breaks. 76 00:05:15,760 --> 00:05:17,030 And that's it. 77 00:05:17,050 --> 00:05:19,720 I hope you enjoyed this breakpoint session.