Print the number series 1 3 6 using for loop in Java
for Loop - Question 5
In this question, we will see how to print the number series 1 3 6... in Java programming using for loop. To know more about for loop click on the for loop lesson.
Q5) Write a program in Java to print the number series given below using for loop.
1 3 6 10 15 21 28 36 45 55
Program
public class Q5
{
public static void main(String args[])
{
int i,s=0;
for(i=1; i<=10; i=i+1)
{
s=s+i;
System.out.print(s + " ");
}
}
}
Output
1 3 6 10 15 21 28 36 45 55