how can i write code for output like this:

Anuradha Mandal commented: Try some code by yourself and post it. +0

``````for i 1 to 5
{
for j i to 5
{
print i
}
nextline
}``````

CDo you have done a programe to print a pyramid of "1" like.....
1
1 1
1 1 1
1 1 1 1
or.....
1 1 1 1
1 1 1
1 1
1
??????????????????????
First wright some code yourself weather it is wrong or right.

Before coding just develop your logic.

@Onlineshade: You do not need to post a useless comment on every single thread that you drag up.

Hello Ezzaral,

You do not need to post a useless comment on every single thread that you drag up.

chamnab has just post his or her problem. He does not put any effort on it. So I cant give him the code directly .It will break the rule.

I'm fairly aware of the rules, thanks.

Ezzaral is right, just what are u posting @onlineshade, "develop logic before coding", does he posted any code yet... So When he hasnt coded anything how can u give such comments.

@chamnab: What's most important in these problems is to break a big problem down into smaller problems.

Starting with that we want to produce this output:

``````1     1 2 3 4 5                        1
1 1       1 2 3 4                      1 2 1
1 2 1         1 2 3                    1 2 3 2 1
1 2 3 1           1 2                  1 2 3 4 3 2 1
1 2 3 4 1             1                1 2 3 4 5 4 3 2 1``````

Let's first focus on this:

``````1
1 1
1 2 1
1 2 3 1
1 2 3 4 1``````

Notice any patterns?

We want to print five lines.

Some things are the same on every line.

Some things are different for each line.

On each line, there is a certain pattern from left to right.

Because of the way Java works, we must produce lines top to bottom, and then left to right.

We could count the lines, from top to bottom, from one to five. Or we could count them, top to bottom, zero to four. Which one would make more sense to you, given the patterns you've seen?

Now within the loop that counts lines, you will know what line you're on. Given that you know what line you're on, could you write the code needed to generate and print the data on that line. Would another loop or two be helpful? :)

Ezzaral is right, just what are u posting @onlineshade, "develop logic before coding", does he posted any code yet... So When he hasnt coded anything how can u give such comments.

As JeffGrigg has replied, this is called logic.
And how the second line has come after the first line , it has to be find out to be a pure programmer.