00:01
In this problem, we're asked to write a program that allows the user to enter 20 numbers, and then we calculate the largest, the smallest, and the average of these 20 numbers, and return it back to the user.
00:13
So first thing we're doing here is initializing our variables.
00:17
We have the scanner variable here.
00:20
I've just called it scan, which will allow us to get user input.
00:25
We also have several integer variables here.
00:29
The first being count, which just basically keeps track of how many numbers the user has entered.
00:39
We have total, which is a running total, and we add the current number each time so that we can calculate the average at the end.
00:49
We have temp, which stores the current number that the user has entered on that particular iteration of the loop.
00:57
So temp is going to be updating.
00:59
Every single time, right? and then we have largest and smallest, which will store the largest of smallest values that the user has entered.
01:12
So basically each time we go through the loop, we got to check if the current number is bigger than largest or smaller than smallest, and if it is, then assign it to those variables.
01:21
That's why we've set largest here to zero, right? because assuming we're only entering positive numbers, anything of be larger than zero, so we'll run into no issues with that in our loop.
01:34
And then same reasoning goes for smallest.
01:36
Really, i put a million here, but you could set it to whatever huge number that you know the user won't be entering anything large than that in the loop.
01:45
So let's look at the actual loop here.
01:48
I did it with the while loop.
01:49
You could also do it with the four loop.
01:51
It doesn't really matter.
01:53
But i've said, well, count is less than 20.
01:55
And then we got to increase count by one each time, right? so the wall loop basically just allows us to run through it 20 times really easily without quite literally, you know, copy and pacing this code 20 times, right? that'd be super inefficient.
02:12
So that's just the point of the while loop and the count variable here...