Program to print 1
1 2
1 2 3
1 2 3 4 like that

Answer Posted / subash chandra bose l

class Tri
{
public static void main(String args[])
{
int i,j,k,sp=30;
for(i=1;i<=5;i++)
{
for(k=0;k<sp;k++)
{
System.out.println(" ");
}
sp=sp-2;
for(j=1;j<=i;j++)
{
System.out.println(" "+j);
}
}
}
}
this will print up to 5 rows and if u want more rows to be
printed you can increase the i<=n where n may be the number
of rows you want to print.

Is This Answer Correct ?    3 Yes 7 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is an empty list in java?

524


What is a parameter in java?

546


When should I use stringbuffer?

571


Objects or references which of them gets garbage collected?

532


Can we catch more than one exception in single catch block?

599






what is meant by Garbage collection?

619


does java support pointers?

565


Can we declare a class as abstract without having any abstract method?

552


How to optimize the javac output?

597


Suppose if we have variable ' I ' in run method, if I can create one or more thread each thread will occupy a separate copy or same variable will be shared?

540


Explain with example the concept of constant variable in java.

632


What are advantages of using Java?s layout managers than windowing systems?

1858


In a program, initializing an array of 100 KB is throwing an out of memory exception while there is 100 MB of memory available. Why?

573


What is nan inf?

506


What is the range of a character variable?

543