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

Answer Posted / ravi jain

public class Test
{
public static void main(String[] args)
{
int sp=5;
for(int n=1;n<=5;n++)
{
for(int s=1;s<=sp;s++)
{
System.out.print(" ");
}
for(int i=1; i<=n;i++)
{
System.out.print(i+" ");
}
System.out.println();
sp--;
}
}
}

Is This Answer Correct ?    13 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Why do we need data structure in java?

572


How do I run java on windows?

530


What are java packages? What is the significance of packages?

569


I have multiple constructors defined in a class. Is it possible to call a constructor from another constructor’s body?

587


Explain the meaning of java applet.

604






Java is pass by value or pass by reference? Explain

534


Explain implementation and how is it different from conversion?

588


What is method overloading in java ?

556


What is the point of polymorphism java?

543


How do I get a substring?

523


What is the use of StringTokenizer class?

607


What does || mean in code?

543


What are methods of a class?

542


Why does my function print none?

516


How can we use primitive data types as objects?

556