Before we start, did you try solving the workbook yourself?
If not, please click the link in the resources folder and follow the instructions for this workbook.
Welcome to Work Book 5.2.
It's telling me to see to learn the part for the instructions.
Let's do just that.
So task one is to ask Bart to enter a line that he wants us to write.
So here we can just say string line.
Got to define scanner first.
Scanner scan is equal to a new scanner instance that can detect input from the system.
Okay, so string line is equal to skin dot next line.
All right?
And whatever Bart asks us to print, we need to print it 99 times.
And it also tells us to number each line starting from one.
All right, So our start index needs to be one, and I is equal to one.
We want the last number to be 99.
Right.
So you would want to say I is smaller than 100 or I is smaller than or equal to 99.
It doesn't really matter which one you choose because both conditions will accept a value of 99 and
both conditions will reject a value of 100.
So you choose which one that you want to go for.
I will go for this one, and then I will just print.
I.
Followed by a dot.
And whatever Bart asks us to print.
All right, Now I'm going to visualize the runtime.
What do you want me to write?
I'm guessing we'll just put.
I will not forget semicolons.
All right.
So I start at one.
One is smaller than or equal to 99.
So this four loop is going to run printing the following message.
We're off to a good start because our number starts from one as was instructed.
And now obviously, I'm going to fast forward.
All right, So now I'm at 96, 97.
98.
99.
And now when it goes back, I A-plus plus is going to increase I to then equal 100 100 is not smaller
than or equal to 99, which means our for loop is going to break.
And that is all we've successfully emulated the exact same output inside of learn the part.
It starts from one and it ends at 99 and total printing our message 99 times.
And as always, do not forget to close scanner.
All right.
That is all for workbook 5.2.