In: Computer Science
Using Eclipse
(Pyramid) Print out the following pyramid using nested loop.
1
12
123
1234
12345
1) the source code (.java file), and
2) the screenshot of running results of each question.
Here is the answer...
Code:
class Pyramid
{
public static void main(String[] args) {
int n=5;
//give n
value as your wish
for(int
i=1;i<=n;i++)
//for number of rows
{
for(int
j=1;j<=i;j++)
//printing numbers in each row
{
System.out.print(j);
}
System.out.println();
//print new line after one row
}
}
}
Code and Output:
If you have any doubts please COMMENT...
If you understand the answer please give THUMBS UP....