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

Answer Posted / rajesh

public class Triangle {

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.print(" ");
}
sp=sp-1;
for(j=1;j<=i;j++)
{
System.out.print(" "+j);
}
System.out.println();
}
}

}

Is This Answer Correct ?    10 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is number data type in java?

558


What is java virtual machine and how it is considered in context of java’s platform independent feature?

655


Can an arraylist be empty?

568


What do you mean by constructor?

549


What’s the difference between constructors and other methods?

531






Can we synchronize static methods in java?

600


Can sleep() method causes another thread to sleep?

568


What is a buffer in java?

573


How do you sort a string in java?

539


Explain the protected field modifier?

593


Why arraylist is used in java?

551


What is an error in java?

641


Can we have two methods in a class with the same name?

582


What is the difference between applet and application?

544


What is floating data type?

539