1 00:00:01,250 --> 00:00:01,550 ‫All right. 2 00:00:01,550 --> 00:00:02,200 ‫Welcome back. 3 00:00:02,210 --> 00:00:08,090 ‫And the last view, we looked at the params keyword and I gave you some simple examples, but they are 4 00:00:08,090 --> 00:00:12,440 ‫not really real world applications, so to speak, of real world examples. 5 00:00:12,440 --> 00:00:18,890 ‫So let's look at the real world example because there is this method called math min. 6 00:00:19,190 --> 00:00:21,440 ‫So let me get rid of a couple of code. 7 00:00:21,440 --> 00:00:23,480 ‫So there is this math class, right? 8 00:00:23,480 --> 00:00:25,790 ‫And it has this min method. 9 00:00:25,970 --> 00:00:32,720 ‫And what it allows us to do is to pass value one and value two and then it will compare those two and 10 00:00:32,720 --> 00:00:35,330 ‫will give us the lower one of the two. 11 00:00:35,570 --> 00:00:41,660 ‫You can see you can do the same thing with decimals, doubles, floats and so forth with different kinds 12 00:00:41,660 --> 00:00:43,940 ‫of variable types. 13 00:00:44,210 --> 00:00:48,920 ‫It's basically just different number types that it allows us to use. 14 00:00:49,100 --> 00:00:56,900 ‫So the problem here is that I can only do it with two values, but what if I wanted to give it multiple 15 00:00:56,900 --> 00:01:03,050 ‫different values, not just two, but let's say seven or 15 or however many values I want to pass to 16 00:01:03,050 --> 00:01:09,200 ‫it, and I wanted to have the lowest number and get it returned. 17 00:01:09,470 --> 00:01:12,320 ‫Well, therefore, I would need to create my own method. 18 00:01:12,500 --> 00:01:15,140 ‫And that's what we're going to do in this video. 19 00:01:15,320 --> 00:01:19,250 ‫Now, this will give you another good example of how to use params. 20 00:01:19,250 --> 00:01:22,640 ‫So this will be something that you can very easily re-use in the future. 21 00:01:24,220 --> 00:01:27,280 ‫So let's go ahead and actually create this method. 22 00:01:28,270 --> 00:01:32,380 ‫So I'm going to get rid of these methods here that we created so far. 23 00:01:32,380 --> 00:01:40,180 ‫I'm just going to create this new public static integer min v two method and it will take. 24 00:01:41,430 --> 00:01:45,920 ‫However many programs of type integer as I want. 25 00:01:45,930 --> 00:01:48,600 ‫So I'm just going to call this a numbers. 26 00:01:48,870 --> 00:01:57,870 ‫And what I'm going to do here is I'm going to set my minimum value to be int dot max value. 27 00:01:59,820 --> 00:02:08,100 ‫So that just means that this mean this is not the actual minimum value, but this is the highest possible 28 00:02:08,100 --> 00:02:11,840 ‫value that an integer can have at max value. 29 00:02:11,850 --> 00:02:12,690 ‫You can hover over it. 30 00:02:12,690 --> 00:02:17,220 ‫You can see it's 2 billion, I believe 2 billion, 174 million and so forth. 31 00:02:17,850 --> 00:02:21,900 ‫So that is going to be the maximum value that an integer can hold. 32 00:02:21,990 --> 00:02:28,440 ‫And now I can compare my values that I'm passing to it with this value to see if they are lower than 33 00:02:28,440 --> 00:02:30,070 ‫the maximum value of integers. 34 00:02:30,090 --> 00:02:32,010 ‫That's the idea behind using it here. 35 00:02:32,400 --> 00:02:32,520 ‫Okay. 36 00:02:32,610 --> 00:02:35,550 ‫So I can just use a for each loop now. 37 00:02:35,760 --> 00:02:39,210 ‫Like so I use the tab key and use tab once again. 38 00:02:39,210 --> 00:02:41,550 ‫This will now create this for each loop for me. 39 00:02:41,550 --> 00:02:47,220 ‫And now I can just say, okay, the individual items will be of type integer, I'm going to call them 40 00:02:47,220 --> 00:02:47,880 ‫number. 41 00:02:48,210 --> 00:02:51,150 ‫So it will be an individual number in my collection. 42 00:02:51,150 --> 00:02:53,850 ‫And what is the collection going to be that I want to run through? 43 00:02:53,880 --> 00:02:59,370 ‫Well, it's going to be the numbers that are passed to this method once this method is called. 44 00:03:00,630 --> 00:03:08,190 ‫So this for each loop will now go through every single number that is passed to my method main v two 45 00:03:08,520 --> 00:03:11,280 ‫and it will compare. 46 00:03:11,280 --> 00:03:18,300 ‫So it will check if the number that is passed is going to be lower than the current minimum number. 47 00:03:18,510 --> 00:03:22,650 ‫If that's the case, then set min to the number. 48 00:03:23,410 --> 00:03:28,870 ‫So that means that let's say this max value here is 2 billion, right? 49 00:03:28,870 --> 00:03:33,280 ‫And now let's say I pass a value that is 5000, for example. 50 00:03:33,580 --> 00:03:36,070 ‫So now 5000 will be checked. 51 00:03:36,070 --> 00:03:39,020 ‫Is 5000 less than 2 billion? 52 00:03:39,040 --> 00:03:39,900 ‫Yes, that's the case. 53 00:03:40,210 --> 00:03:44,380 ‫So now the lowest number will be 5000. 54 00:03:44,500 --> 00:03:47,500 ‫So we assign 5000 to be this mean number. 55 00:03:48,370 --> 00:03:52,720 ‫Now we can just go ahead and return our min number. 56 00:03:53,380 --> 00:03:55,150 ‫So this integer min. 57 00:03:55,980 --> 00:03:56,190 ‫I. 58 00:03:56,190 --> 00:03:57,480 ‫Now this error should disappear. 59 00:03:57,480 --> 00:03:59,460 ‫So now our method should be happy. 60 00:03:59,550 --> 00:04:05,520 ‫So now the cool thing is you can throw as many values as you want to it. 61 00:04:05,820 --> 00:04:08,910 ‫So, actually, let me show you. 62 00:04:08,940 --> 00:04:14,550 ‫Here we are going to pass seven values, 6428, zero one and five. 63 00:04:14,550 --> 00:04:21,030 ‫And then we are going to print out whatever the minimum value is because we can now assign the result 64 00:04:21,030 --> 00:04:29,100 ‫of our movie to call with all of those values into an integer, because our min value will return an 65 00:04:29,100 --> 00:04:29,850 ‫integer. 66 00:04:30,000 --> 00:04:35,140 ‫So it will basically just return a number and we can assign a number to an integer variable. 67 00:04:35,160 --> 00:04:36,960 ‫So that's what we're doing in this line. 68 00:04:37,920 --> 00:04:45,090 ‫And now we can just take this number and display it using the string that we have here. 69 00:04:45,090 --> 00:04:46,920 ‫So our right line statement. 70 00:04:46,980 --> 00:04:49,790 ‫So out of these numbers, what will be the minimum number? 71 00:04:49,800 --> 00:04:51,630 ‫Well, it will be zero. 72 00:04:52,830 --> 00:04:56,820 ‫So actually, let's do it like this looks a little better. 73 00:04:57,340 --> 00:04:57,530 ‫Okay. 74 00:04:57,540 --> 00:05:00,210 ‫So this will now return our minimum number zero. 75 00:05:00,210 --> 00:05:04,350 ‫But what if we wanted to assign different kind of values? 76 00:05:04,740 --> 00:05:06,150 ‫So let's run it again. 77 00:05:06,150 --> 00:05:11,280 ‫But this time we're going to assign even negative values. 78 00:05:11,280 --> 00:05:14,220 ‫So here, 510. 79 00:05:14,400 --> 00:05:18,360 ‫And of course, this has to be an integer like so now let's run it once again. 80 00:05:20,020 --> 00:05:28,930 ‫And you can see it says the minimum is -11 because a negative value is going to be a smaller than all 81 00:05:28,930 --> 00:05:34,480 ‫of the positive values that are inside of our list of arrays that we're passing. 82 00:05:34,480 --> 00:05:37,870 ‫So you see, this time we are passing five values. 83 00:05:37,870 --> 00:05:41,770 ‫So we're not passing just well, the seven values that we had before. 84 00:05:41,800 --> 00:05:44,020 ‫You could go ahead and pass as many as you want. 85 00:05:44,020 --> 00:05:52,480 ‫You can go ahead and even do something like one, three, 37, 42, 69 for 20. 86 00:05:53,240 --> 00:05:54,350 ‫404. 87 00:05:54,440 --> 00:05:55,820 ‫And all the good stuff. 88 00:05:55,850 --> 00:05:57,530 ‫You could put all of them in here. 89 00:05:57,530 --> 00:06:01,400 ‫And, well, the minimum number will still be -11, of course. 90 00:06:01,400 --> 00:06:02,720 ‫So let's get rid of that. 91 00:06:02,720 --> 00:06:04,160 ‫Let's get rid of the zero. 92 00:06:04,160 --> 00:06:06,200 ‫And let's actually just keep. 93 00:06:07,060 --> 00:06:10,540 ‫The cool numbers in here and let's run it again. 94 00:06:10,900 --> 00:06:12,610 ‫Well, still just five values. 95 00:06:12,760 --> 00:06:16,540 ‫But yeah, it's going to say the solution is 42. 96 00:06:16,990 --> 00:06:19,360 ‫So for all of the techies out there. 97 00:06:20,260 --> 00:06:23,310 ‫That should say something for you or to you. 98 00:06:23,320 --> 00:06:30,070 ‫So if we made this list negative, then of course, minus one, three, three seven will be the minimum 99 00:06:30,070 --> 00:06:30,570 ‫value. 100 00:06:30,580 --> 00:06:34,330 ‫But yeah, you can now go ahead and pass as many values as you want. 101 00:06:34,360 --> 00:06:39,610 ‫Now imagine you don't type those values in manually, but you get them from a database. 102 00:06:39,610 --> 00:06:42,220 ‫So you get a bunch of data from a database. 103 00:06:42,220 --> 00:06:46,330 ‫Probably you would get it in an array format and then you pass it in here. 104 00:06:46,330 --> 00:06:52,180 ‫Maybe you get or you have multiple sources and you want to combine the two sources and you want to compare 105 00:06:52,180 --> 00:07:00,940 ‫all of the sources together, and you want to compare them in a way where you then get the minimum number. 106 00:07:01,240 --> 00:07:06,100 ‫Or the cool thing is you can still do that using the params keyword. 107 00:07:06,130 --> 00:07:10,990 ‫Of course the method would look a little different, but yeah, you could basically do that. 108 00:07:14,110 --> 00:07:14,470 ‫All right. 109 00:07:14,470 --> 00:07:20,860 ‫So summing it up using terms is quite useful when we have a method that can take any number of parameters, 110 00:07:20,860 --> 00:07:26,050 ‫and it's a good tool that must be in our arsenal as developers. 111 00:07:27,130 --> 00:07:29,260 ‫Okay, so see you in the next video.