3.5 Count Program

Video Activity
Join over 3 million cybersecurity professionals advancing their career
Sign up with
Required fields are marked with an *
or

Already have an account? Sign In »

Time
4 hours 19 minutes
Difficulty
Beginner
CEU/CPE
4
Video Transcription
00:00
Hi and welcome back to the course.
00:02
Now, in the last video lecture, we went over the concept of four loops. And in this lab, which is our second lab for the third module, we're gonna be going over a count program, and we're going to be creating a con program in which we will be implementing our knowledge and newly learned concept of four loops.
00:22
So, as I mentioned just a few seconds earlier, the learning objective for this live is to use a four loop to print numbers from 0 to 10.
00:34
All right, Perfect. So at this moment, I'd like you to go ahead and switch over to intelligence.
00:40
Now an intelligent we will, as always, go on file new and then project to create a new project. And then you'll first encounter this window over here,
00:51
and right after that, we'll click next, leaving all the default settings
00:56
on this page also click next,
00:59
and then we will arrive at the project name and project location page.
01:03
So what I would like to do is store my program in a folder called Count Program, and I'll just in fact do that right in front of you. So I'm gonna go into my cyber folder on module three.
01:18
And then I would like to create a new folder
01:23
on Let's name this
01:26
count
01:27
program.
01:29
Perfect.
01:30
Now what we're gonna do is we're gonna click on these three little dogs, which will let us open and specify the path in which we would like the store, our program.
01:41
And then all you have to do is click on count program,
01:46
as I have discussed earlier in previous videos. All this lets you do is save your project in a specific folder which keeps things organized. Well, at least that's what it does for me. And then hopefully it'll help you do the same.
02:00
Then what we're gonna do is go ahead and click. Finish.
02:04
It will ask you if you'd like to replace this window or a new one. Just click on new window.
02:10
All right. Perfect. Uh, see if we can maximize this. No. Okay, no problem.
02:15
So now what we're gonna do is we're gonna create a new class
02:21
and let's keep all the names same like we have previously.
02:25
Andi, that's click enter.
02:30
All right, so I like to think to yourself and
02:34
ask yourself ask yourself what it is that
02:37
I have previously told you in labs to do before
02:40
starting or starting to write your code in an actual class or program.
02:49
Now, if you're thinking along the lines of doing a quick system dot out that print line to law, uh, something to the consul than that is correct.
03:00
So what we want to do is we want to make a main method which is done so public static, void, main
03:08
string,
03:12
and then
03:13
energy s pistons for arguments.
03:15
And then I'm gonna have a simple system about out doc print line
03:20
just to see if my class is
03:24
printing something simple and working as it's supposed to work.
03:30
Now you can go ahead and run the class they're here,
03:35
or what you do is right. Click on your Count program Java file and then
03:40
press run count program Dog me.
03:46
Perfect. Know what that does? Is it prints Hello, world for us.
03:50
And now what we would like to do is move on to our actual program.
03:54
So what is the goal of our program? If we were to break it down, what would we say?
04:00
All right, so that's that's right.
04:03
Some basic comments. We need
04:06
a loop.
04:09
Um, and we know which kind of loop it is. It's a four loop, so we need a four loop,
04:15
and
04:16
it needs to print numbers from zero.
04:21
Let's do that. Needs to print
04:25
numbers from
04:28
zero through 10
04:30
10 inclusive
04:33
clues if
04:35
perfect.
04:39
And then
04:40
we need to somehow
04:42
start at zero
04:46
and then
04:46
terminate
04:49
after 10.
04:53
And then we also need thio increments,
04:56
a value which goes from 1 to 2 to three to fort and just increments the index of the four loop.
05:05
All right, so this is essentially all we need to do and let's just get to it.
05:12
So first we have the four key word.
05:15
Then what we need to do is we need to have an initial Isar so you can name it anything, and it is an integer since we will be starting from zero. So we would say in't I
05:27
or Eisa Jen is generally used as the indexing four loops I for index. And, um, I'm gonna make that equals zero
05:36
that will satisfy satisfy our condition over here.
05:41
Then
05:42
what I need to say is I less than
05:46
11
05:48
and then I plus Plus.
05:51
Now I less than 11 means that it will go through
05:55
0 to 11 and assuming as it reaches 11 it'll terminate and I plus plus, is the incremental value condition that we defined in our comment section over here.
06:10
Now course, I'd like to see my results in print them out. And in order to do that, we simply have to say,
06:16
We could have something neat like this so we could say
06:19
numbers
06:21
and then plus
06:24
I
06:27
then we could also do is we could add a, uh,
06:31
we could add a slash in which mean eyes Ah, keyword used for new line. So that will just put it
06:42
underneath each number in a straight vertical line. Let's see if that works.
06:48
All right,
06:50
Perfect. So as you can see,
06:54
what's happening is
06:56
I'm printing out the numbers.
06:58
Andi, it says number zero numbers. One numbers, two numbers. Three. And it goes all the way till 10
07:03
right until offer 10. When it reaches 11 it terminates the program.
07:09
So that was a quick, short and simple weight of
07:13
playing around with four loose. But there's many other avenues you could have taken
07:17
so to summarize everything in this video lecturer lab. We discussed the implementation of four loose by creating a counter program
07:26
and the syntax off for Loop four loops, which includes the initial Isar, a condition
07:32
for the termination and implementation.
07:38
And in the next video, Elektra, we will be going over the switch statement.
07:42
Now is always if you have any questions at all, feel free to contact me. And I'd be more than happy to answer any of your questions. Thank you very much for watching. And I will see you in the next video lecture.
Up Next