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 / pravin pawar

public static void main(String args[])
{
for(int r=1;r<=5;r++)
{
for(int s=5-r;s>0;s--)

System.out.print(" ");

for(int c=r;c>=1;c--)
System.out.print(c);

for(int c=2;c<=r;c++)

System.out.print(c);

System.out.print("\n");
}
}

Is This Answer Correct ?    8 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is encapsulation c#?

613


This program numbers the lines found in a text file. Write a program that reads text from a file and outputs each line preceded by a line number. Print the line number right-adjusted in a field of 3 spaces. Follow the line number with a colon, then one space, then the text of the line. You should get a character at a time and write code to ignore leading blanks on each line. You may assume that the lines are short enough to fit within a line on the screen. Otherwise, allow default printer or screen output behavior if the line is too long (i.e., wrap or truncate). A somewhat harder version determines the number of spaces needed in the field for the line numbers by counting lines before processing the lines of the file. This version of the program should insert a new line after the last complete word that will fit within a 72-character line.

1645


Why is polymorphism needed?

609


what is graphics

2022


What is constructor in oop?

593






Why do we use class?

646


What is polymorphism give a real life example?

572


What do you mean by variable?

583


assume the program must insert 4 elements from the key board and then do the following programs.sequential search(search one of the elements),using insertion sort(sort the element) and using selection sort(sort the element).

1679


What are the data types in oop?

615


What do you mean by overloading?

592


What is destructor give example?

612


What is purpose of inheritance?

653


What is polymorphism used for?

583


Can we have inheritance without polymorphism?

625