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
What is encapsulation c#?
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.
Why is polymorphism needed?
what is graphics
What is constructor in oop?
Why do we use class?
What is polymorphism give a real life example?
What do you mean by variable?
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).
What are the data types in oop?
What do you mean by overloading?
What is destructor give example?
What is purpose of inheritance?
What is polymorphism used for?
Can we have inheritance without polymorphism?