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 is the old name of java?
What's the purpose of using break in each case of switch statement?
Is java se free?
Garbage collection in java?
Java.util.regex consists of which classes?
What is boolean keyword in java?
What is extension method in java?
What are the special characters?
What is the difference between Error, defect,fault, failure and mistake?
Which sort is best in java?
How to overcome the exception object reference not set to an instance of object?
Why singleton pattern is better than creating singleton class with static instance?
What does a method signature consist of?
what is nested class in java?
Can we use catch statement for checked exceptions?