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
What are the procedures?
What do you mean by boolean?
What is a jit compiler?
Why do we need data structure in java?
What is the default value of byte datatype in java?
What is parse method?
What is the best way to findout the time/memory consuming process?
In how many ways we can do exception handling in java?
Can a method be overloaded based on different return type but same argument type?
Can we extend singleton class in java?
What is the right data type to represent a price in java?
Is java written in c?
What is meant by method overriding?
What are recursive functions? Give some examples?
Can constructor be protected in java?