Write a program to accept a number and to print numbers in
pyramid format?
for eg:for a no. 5
1
212
32123
4321234
543212345

Answer Posted / rathod rajesh

for(int i=1;i<=5;i++)
{
for(int k=5;k>=i;k--)
{
System.out.print(" ");
}

for(int j=i;j>=1;j--)
{
System.out.print(j);
}
for(int j=2;j<=i;j++)
{
System.out.print(j);
}
System.out.println();

}

Is This Answer Correct ?    2 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Why do we use oops?

593


What is polymorphism and its types?

599


Why do while loop is used?

579


Which method cannot be overridden?

584


What is abstraction with example?

608






What is inheritance in simple words?

627


What is overriding in oops?

606


When not to use object oriented programming?

572


Why multiple inheritance is not allowed?

586


What does I oop mean?

618


What is overloading in oops?

598


What is encapsulation oop?

578


What is the example of polymorphism?

562


What is polymorphism in oops with example?

533


Give an example where we have to specifically use C programming language and C++ programming language cannot be used?

1149