Â
In this, we are going to write a program to print the 1, 2, 4, 7, 11, 16, … up to n in series in Java.
import java.util.*;
class Series7
{
public static void main(String[] args)
{
int i, n, s = 1;
Scanner sc = new Scanner(System.in);
System.out.print("Enter the number of terms:");
n = sc.nextInt();
for (i = 1; i <= n; i++)
{
System.out.print(s + " ");
s = s + i;
}
}
}
#ENJOY CODING
Post a Comment
FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP