1 00:00:00,510 --> 00:00:01,350 ‫Welcome back. 2 00:00:01,380 --> 00:00:07,040 ‫In this video, we are going to have a look at a race and several ways of creating and using a race. 3 00:00:07,050 --> 00:00:08,600 ‫So let's get started. 4 00:00:08,610 --> 00:00:14,960 ‫We are in a main method again and in here I will create an integer array. 5 00:00:14,970 --> 00:00:17,850 ‫So let's just create one and I'm going to call that one. 6 00:00:17,850 --> 00:00:18,690 ‫Great. 7 00:00:18,870 --> 00:00:25,110 ‫And this is going to be a new int five array. 8 00:00:25,290 --> 00:00:33,210 ‫Now that means that we have an array which is of type integer and it has five values or at least has 9 00:00:33,210 --> 00:00:34,560 ‫a space for five values. 10 00:00:34,560 --> 00:00:41,160 ‫So we define straight away how many different values we want to store in that array in order to add 11 00:00:41,160 --> 00:00:42,360 ‫those values to the array. 12 00:00:42,360 --> 00:00:43,560 ‫We have multiple ways. 13 00:00:43,560 --> 00:00:50,820 ‫So one would be we assign at a specific index, we assign a specific value. 14 00:00:50,820 --> 00:00:58,140 ‫So let's say one is a great student and he has 20 points or we has a grade of 20. 15 00:00:58,410 --> 00:01:05,580 ‫Then the second grade is going to be, let's say 15 and so forth. 16 00:01:05,580 --> 00:01:13,500 ‫So now I can go ahead and I can add the grade to my array and I always have to be specific with the 17 00:01:13,500 --> 00:01:14,160 ‫index. 18 00:01:14,160 --> 00:01:21,990 ‫So from 0 to 4, those are the five values that I want to add to the array of grades. 19 00:01:21,990 --> 00:01:25,230 ‫And of course, I could change the values up a little bit. 20 00:01:25,230 --> 00:01:31,380 ‫So it's not going to be all great students, but some have worse marks as well. 21 00:01:32,070 --> 00:01:32,580 ‫All right. 22 00:01:32,580 --> 00:01:39,300 ‫So that's generally how you can create an array, so how you can initialize it, how you can add the 23 00:01:39,300 --> 00:01:42,270 ‫values, and now in order to access it. 24 00:01:42,270 --> 00:01:44,220 ‫So let's just access it. 25 00:01:44,220 --> 00:01:51,360 ‫And I'm going to use see W which is a code snippet for console, right line double tap and I get console 26 00:01:51,360 --> 00:01:58,770 ‫right down and here I simply say grades at index zero. 27 00:01:59,070 --> 00:02:06,300 ‫And in here we use the curly brackets again at the position zero and that will be great. 28 00:02:07,050 --> 00:02:09,690 ‫So as you see, it always starts off at zero. 29 00:02:09,690 --> 00:02:12,440 ‫So computers, they start counting at zero. 30 00:02:12,450 --> 00:02:13,500 ‫That's the point here. 31 00:02:13,500 --> 00:02:15,330 ‫So that alone will not be enough. 32 00:02:15,330 --> 00:02:17,280 ‫We want to see the console as well. 33 00:02:17,280 --> 00:02:20,850 ‫So console the read key 34 00:02:23,640 --> 00:02:25,500 ‫and now let's see again. 35 00:02:25,860 --> 00:02:29,010 ‫Great at index zero is 20. 36 00:02:29,610 --> 00:02:29,910 ‫All right. 37 00:02:29,910 --> 00:02:31,530 ‫And that's exactly what we have here. 38 00:02:31,530 --> 00:02:33,390 ‫So this is how you can access it. 39 00:02:33,390 --> 00:02:37,230 ‫And if you want like to change it afterwards, you can do so. 40 00:02:37,230 --> 00:02:45,030 ‫So let's say somebody presses the key and I want to change the value and I want to give it out again. 41 00:02:45,030 --> 00:02:56,430 ‫So here I just say, great, or actually let's get the value the user enters and let's make an integer 42 00:02:56,430 --> 00:02:57,030 ‫out of it. 43 00:02:57,030 --> 00:03:07,500 ‫So we just say string input is equal to console dot red line and now we need to make sure that the input 44 00:03:07,680 --> 00:03:13,230 ‫is transferred to an integer because grades can only contain ints. 45 00:03:13,230 --> 00:03:20,280 ‫So we have to make sure that grades at the position is going to be an actual integer. 46 00:03:20,940 --> 00:03:22,290 ‫So how do we do that? 47 00:03:22,440 --> 00:03:23,610 ‫Can you still remember? 48 00:03:24,480 --> 00:03:27,810 ‫So this one will be the insecure version. 49 00:03:27,900 --> 00:03:30,720 ‫So try parse would be the safer version. 50 00:03:30,720 --> 00:03:36,150 ‫But I'm just going to use Parse now because I know that I'm just going to enter a whole numbers. 51 00:03:36,240 --> 00:03:40,200 ‫So in here I will parse the input. 52 00:03:42,390 --> 00:03:42,720 ‫Now. 53 00:03:42,720 --> 00:03:43,740 ‫Let's check it out. 54 00:03:46,460 --> 00:03:48,450 ‫Rates at index zero is 20. 55 00:03:48,470 --> 00:03:52,870 ‫Now let's say we changed it to ten, creates an index, zero is ten now. 56 00:03:52,880 --> 00:03:56,900 ‫So this is how you can simply change the value any time, right? 57 00:03:58,610 --> 00:04:02,390 ‫So here you assign in this line, I assign a value. 58 00:04:03,710 --> 00:04:09,890 ‫Assign value to array great at index zero. 59 00:04:11,270 --> 00:04:13,970 ‫And here we declare and initialize. 60 00:04:14,360 --> 00:04:14,780 ‫All right. 61 00:04:15,380 --> 00:04:20,900 ‫There are, however, different ways to create arrays or to initialize arrays. 62 00:04:20,900 --> 00:04:22,850 ‫So these are the ones that we've seen. 63 00:04:22,850 --> 00:04:24,350 ‫Now let's check out others. 64 00:04:24,350 --> 00:04:34,220 ‫So let's say we have another array and we call it grades of math students A and that will be in curly 65 00:04:34,220 --> 00:04:36,140 ‫brackets, the values that I want to assign. 66 00:04:36,140 --> 00:04:41,930 ‫So let's say I have 20, 13, 12, eight, eight. 67 00:04:42,440 --> 00:04:46,940 ‫So these are the values that my students of Class A have. 68 00:04:47,420 --> 00:04:49,640 ‫So that's another way of initializing. 69 00:04:50,390 --> 00:05:01,550 ‫And then there is a third way and that's again the data type square brackets, and then you enter the 70 00:05:01,550 --> 00:05:04,820 ‫name again, great of math students. 71 00:05:04,850 --> 00:05:12,980 ‫B And that will be a new int and here I declare double where I enter the values again. 72 00:05:13,160 --> 00:05:18,500 ‫So 1520 317 73 00:05:19,940 --> 00:05:22,070 ‫actually 20 will be the highest value. 74 00:05:22,070 --> 00:05:26,840 ‫So let's say these are the other values that I have. 75 00:05:26,840 --> 00:05:33,080 ‫So as you can see this array here, so grades of math students B has a length of six. 76 00:05:33,080 --> 00:05:37,790 ‫So there are six values and students A is only five values. 77 00:05:37,790 --> 00:05:43,310 ‫So in order to get the length of an array, you can use the array name. 78 00:05:43,310 --> 00:05:46,940 ‫So grades of students, a dot length. 79 00:05:47,120 --> 00:05:54,620 ‫As you can see, there is a property called length and gets a total number of elements in all the dimensions 80 00:05:54,620 --> 00:05:55,250 ‫of the array. 81 00:05:55,250 --> 00:05:57,710 ‫So let's print that out onto the console. 82 00:05:57,740 --> 00:06:04,070 ‫So I'm just going to use CW tab, tab and in here I'm going to just say. 83 00:06:05,650 --> 00:06:10,510 ‫Length of rates or actually I copied that. 84 00:06:10,900 --> 00:06:12,730 ‫No, I did not copy it. 85 00:06:13,120 --> 00:06:21,790 ‫And that will be the value of great length or great of my students at length. 86 00:06:22,090 --> 00:06:25,360 ‫And again, I'm going to use Red Key here. 87 00:06:25,510 --> 00:06:26,350 ‫Now let's run it. 88 00:06:27,640 --> 00:06:30,070 ‫And here I just need to enter something again. 89 00:06:30,070 --> 00:06:30,850 ‫I'm going to use that. 90 00:06:30,850 --> 00:06:34,840 ‫And then the length of grades of math Student A is five. 91 00:06:34,840 --> 00:06:39,040 ‫So we have five values in there and that's exactly what we got in here. 92 00:06:39,040 --> 00:06:46,900 ‫So in order to get the length and you just use the property length, that will come in handy quite often. 93 00:06:46,900 --> 00:06:49,290 ‫So it's really important to understand that concept. 94 00:06:49,300 --> 00:06:55,420 ‫So in the next video we are going to have a look at for each loops I told you about for each loops as 95 00:06:55,420 --> 00:06:57,460 ‫we were talking about loops in general. 96 00:06:57,460 --> 00:07:03,430 ‫But I haven't covered it yet because we needed to understand the concept of race first and that's why 97 00:07:03,430 --> 00:07:05,950 ‫we're going to start off with for each in the next video. 98 00:07:05,950 --> 00:07:07,000 ‫So see there.