‫All right.
‫Welcome back.
‫And the last view, we looked at the params keyword and I gave you some simple examples, but they are
‫not really real world applications, so to speak, of real world examples.
‫So let's look at the real world example because there is this method called math min.
‫So let me get rid of a couple of code.
‫So there is this math class, right?
‫And it has this min method.
‫And what it allows us to do is to pass value one and value two and then it will compare those two and
‫will give us the lower one of the two.
‫You can see you can do the same thing with decimals, doubles, floats and so forth with different kinds
‫of variable types.
‫It's basically just different number types that it allows us to use.
‫So the problem here is that I can only do it with two values, but what if I wanted to give it multiple
‫different values, not just two, but let's say seven or 15 or however many values I want to pass to
‫it, and I wanted to have the lowest number and get it returned.
‫Well, therefore, I would need to create my own method.
‫And that's what we're going to do in this video.
‫Now, this will give you another good example of how to use params.
‫So this will be something that you can very easily re-use in the future.
‫So let's go ahead and actually create this method.
‫So I'm going to get rid of these methods here that we created so far.
‫I'm just going to create this new public static integer min v two method and it will take.
‫However many programs of type integer as I want.
‫So I'm just going to call this a numbers.
‫And what I'm going to do here is I'm going to set my minimum value to be int dot max value.
‫So that just means that this mean this is not the actual minimum value, but this is the highest possible
‫value that an integer can have at max value.
‫You can hover over it.
‫You can see it's 2 billion, I believe 2 billion, 174 million and so forth.
‫So that is going to be the maximum value that an integer can hold.
‫And now I can compare my values that I'm passing to it with this value to see if they are lower than
‫the maximum value of integers.
‫That's the idea behind using it here.
‫Okay.
‫So I can just use a for each loop now.
‫Like so I use the tab key and use tab once again.
‫This will now create this for each loop for me.
‫And now I can just say, okay, the individual items will be of type integer, I'm going to call them
‫number.
‫So it will be an individual number in my collection.
‫And what is the collection going to be that I want to run through?
‫Well, it's going to be the numbers that are passed to this method once this method is called.
‫So this for each loop will now go through every single number that is passed to my method main v two
‫and it will compare.
‫So it will check if the number that is passed is going to be lower than the current minimum number.
‫If that's the case, then set min to the number.
‫So that means that let's say this max value here is 2 billion, right?
‫And now let's say I pass a value that is 5000, for example.
‫So now 5000 will be checked.
‫Is 5000 less than 2 billion?
‫Yes, that's the case.
‫So now the lowest number will be 5000.
‫So we assign 5000 to be this mean number.
‫Now we can just go ahead and return our min number.
‫So this integer min.
‫I.
‫Now this error should disappear.
‫So now our method should be happy.
‫So now the cool thing is you can throw as many values as you want to it.
‫So, actually, let me show you.
‫Here we are going to pass seven values, 6428, zero one and five.
‫And then we are going to print out whatever the minimum value is because we can now assign the result
‫of our movie to call with all of those values into an integer, because our min value will return an
‫integer.
‫So it will basically just return a number and we can assign a number to an integer variable.
‫So that's what we're doing in this line.
‫And now we can just take this number and display it using the string that we have here.
‫So our right line statement.
‫So out of these numbers, what will be the minimum number?
‫Well, it will be zero.
‫So actually, let's do it like this looks a little better.
‫Okay.
‫So this will now return our minimum number zero.
‫But what if we wanted to assign different kind of values?
‫So let's run it again.
‫But this time we're going to assign even negative values.
‫So here, 510.
‫And of course, this has to be an integer like so now let's run it once again.
‫And you can see it says the minimum is -11 because a negative value is going to be a smaller than all
‫of the positive values that are inside of our list of arrays that we're passing.
‫So you see, this time we are passing five values.
‫So we're not passing just well, the seven values that we had before.
‫You could go ahead and pass as many as you want.
‫You can go ahead and even do something like one, three, 37, 42, 69 for 20.
‫404.
‫And all the good stuff.
‫You could put all of them in here.
‫And, well, the minimum number will still be -11, of course.
‫So let's get rid of that.
‫Let's get rid of the zero.
‫And let's actually just keep.
‫The cool numbers in here and let's run it again.
‫Well, still just five values.
‫But yeah, it's going to say the solution is 42.
‫So for all of the techies out there.
‫That should say something for you or to you.
‫So if we made this list negative, then of course, minus one, three, three seven will be the minimum
‫value.
‫But yeah, you can now go ahead and pass as many values as you want.
‫Now imagine you don't type those values in manually, but you get them from a database.
‫So you get a bunch of data from a database.
‫Probably you would get it in an array format and then you pass it in here.
‫Maybe you get or you have multiple sources and you want to combine the two sources and you want to compare
‫all of the sources together, and you want to compare them in a way where you then get the minimum number.
‫Or the cool thing is you can still do that using the params keyword.
‫Of course the method would look a little different, but yeah, you could basically do that.
‫All right.
‫So summing it up using terms is quite useful when we have a method that can take any number of parameters,
‫and it's a good tool that must be in our arsenal as developers.
‫Okay, so see you in the next video.