‫Hello my friends, and welcome to coding Exercise number eight.
‫In this exercise, we are asked to write a program to make such a pattern, like a pyramid with a number
‫which will repeat the number in the same row.
‫For example, the user enter the number of rows is equal to four.
‫That program will print one at the top, 2 to 3 threes for fours.
‫So I need from you to think about how to create such a pattern.
‫The user enter number.
‫It will be printing a pyramid like this pattern.
‫Just one hint, please, guys, think about nested loops.
‫I'm waiting your solutions in the comment below in order to solve and check it for any error and help
‫you in any misunderstanding of concepts.
‫I hope you solve it.
‫Well, now let's start solving this problem.
‫I will create four variables, five variables of type int I and J for that loop.
‫And X.
‫And as for the number entered by the user and as the sum here.
‫So.
‫I will start by getting the user input.
‫So I will use I will display a message for the user.
‫Please enter a number and in order to get the data from the user and the input from the user, we need
‫our friend scanner.
‫So scanner scan or SW one equal to nu scanner system dot nw
‫SW one dot or NW equal to SW one dot next int OC.
‫Now.
‫S equal to N plus four minus one, because if I entered four, the user entered for four plus four.
‫Eight minus one as seven.
‫So I need to repeat this seven for the seven.
‫So this is the number of spaces.
‫Some of the spaces I want from you to concentrate with me now for.
‫I.
‫Equal to one I less than or equal to nn the third the number by the user.
‫I plus plus I need to go and loop through this loop.
‫But since I need to print three things the spaces, the number and the rows.
‫So I need to create three loops.
‫This is for the rows.
‫This the outer loop.
‫This is for the spaces.
‫Sorry for the rows.
‫Now I will create a for loop starting by x equal to as the spaces x does not equal to zero and x minus
‫minus.
‫I need to reduce the spaces as long I go down.
‫So the first number one.
‫There are a lot of spaces, but for four, four, four there is no spaces.
‫System.
‫Dot out.
‫Dot print space.
‫I will make this space.
‫This is very important.
‫Another loop, another nested loop inside the outer loop.
‫So this is for the spaces and this loop for printing the numbers.
‫So printing the numbers will start by j equal to one j less than or equal to I and J plus plus what
‫I need to print.
‫I need to print the numbers so I will print the number here, print I plus space.
‫So I print the space here system dot out dot print l nn and then I will put s minus minus oc.
‫Therefore I created a big loop, a an outer loop that is used for printing the rows and determine the
‫number of the rows the user enter for.
‫So it will displace for the user four rows.
‫This will display the spaces and this will display the numbers.
‫Please pay attention for this space.
‫So it may be confusing for you that we have used this space and we count the number of spaces here,
‫but there is an extra space here with the numbers.
‫So every number there is space between between the two numbers like four, four, four, four.
‫There is a space between them.
‫Let's run our program and see.
‫How it looks.
‫Please enter the A number I will print out or enter number four.
‫It will give me one, two, three, four.
‫The first.
‫Throw the first loop.
‫Sorry.
‫It will determine for us how many rows we need to make.
‫We need to make four.
‫So I will create four rules.
‫This is the outer loop.
‫I'm talking about this, that it's indexed by the spaces here.
‫If we click on this, it will give us the number of spaces.
‫So one, two, three, four, five, six and seven here.
‫So seven here.
‫And how many numbers it start by it start by.
‫AJ equal to one, it will print one.
‫It's stopped by two, so it will be printing to OC until j less than or equal to I as one.
‫At first I is equal to two.
‫I is equal to three.
‫I is equal to four in the fourth line and so on.
‫So we need to print the number according to the number or the line number.
‫So this the nine number or row number one, I will print one one time.
‫We are on the row number four, I need to print four four times.
‫And so this is about iteration and this is about making shapes.
‫And I hope you understand how the iteration and how the loops works and used for making complex things.
‫And I want from you to write these down, these examples down, and to memorize them later on when you
‫try to review what we have done.