00:01
All right, for this question we're asked to write a program in java that inputs a series of numbers one by one, and to print the count and the average of the numbers, of only the numbers that have three as their last digit.
00:13
And the process of inputting number should stop if the number inputted by the user is negative, right? so the program that we would write here, right, let's say we write a function.
00:28
Or it doesn't even have to be a function.
00:30
We'll just write a main method, right? so first we have an input, right? so i'll assume that, you know, for the sake of writing this out, that you know how to write inputs and, you know, all the initialization stuff, i'll just assume that that has already been done.
00:49
And i'll write the core algorithm that we should be looking at here to help solve the problem.
00:56
All right.
00:56
So the core algorithm, so first the thing it asks us to do, or the last thing it asks us to do is stop inputting numbers if the numbers negative so while the number we're examining currently right so i we could use a scanner and then make a new scanner system in right and then make a scanner out of that and then we'll call that the and then we'll do a num equals scan dot next int right actually i could just write all this out for you so we'll say for better understanding scan equals our scanner this is a scanner object and r equals a new scanner system in all right then we can say an integer or actually actually we'll assume that we're talking about integers here integer nom equals scanner dot next int all right so we got the next integer so now while that that nom is bigger than or equal to zero.
02:17
I actually write a different way.
02:21
We'll do whatever is inside this while loop, right? so if the number is negative, then we will stop.
02:26
So we satisfied one of the requirements of the algorithm already.
02:31
The next thing is to, we're inputing numbers one by one, and we're going to print the count, right? let's say up here we have an int count initialized to zero and an int average also initialized to zero.
02:43
0 and we want to count print the count and average of those numbers that have 3 as your last digit so how are we going to determine if a number has 3 as your last digit well the very last digit is a 10th or the 1's place so let's say we have a number 53 and we have a number 83 and we have a number 103 and just 1 0 0 with a bunch of zeros and 3 we need a common way to find out if 3 is the last digit of all of these and let's say we have a trial that's 72 to make sure that doesn't work for 72 right one of these ways how we can imagine or examine the very last edge of a number no matter what the number is by looking is by looking at remainder and division right so let's say if we divide this by 10 what would we get we would get something like five right and then point 3 to 3 3 3 so the remainder here, when divided by 10, 53, is, or actually, are, sorry, 53 divided by 10, not 53 divided by 3, is going to be 0 .333, or 0 .3, so 3 over 10.
04:08
So we can see that what we get as a remainder is actually 3.
04:11
Let's say we do the same thing over here, right, to one of these bigger numbers.
04:14
So let's say we take 103 divided by 10.
04:20
Then once again, what we get is we get 10 .3, right? three tenths...