Program to output as below formate:
1
2 3
4 5 6
7 8 9 10

Answer Posted / dhananjaya nawarathne

public class formatNumbers {
public static void main(String args[])
{
int k=1;
for(int i=1;i<5;i++)
{
for(int j=0;j<i;j++)
{
System.out.print(k++ + " ");
}
System.out.print("
");
}
}
}

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is abstract class? Explain

597


What is the difference between jdk, jre, and jvm?

576


What are the four corner stones of oop?

549


Why volatile is used in java?

532


Is java call by reference?

534






Is 0 a prime number?

575


What is the use of optional ?

569


Can you give names of Container classes?

1860


What does split function do in java?

539


Why does java doesnt suuport unsigned values?

1800


Can a class have 2 constructors?

503


What is singletonlist in java?

512


What is string example?

597


How do you escape json?

542


Can a main method be overloaded?

575