Â
In this, we are going to write a program to print the 2, 4, 8, 14, 22, 32, … up to n in series in Java.
import java.util.*;
class Series8
{
public static void main(String[] args)
{
int i, n, s = 2, c = 2;
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 + c;
c = c + 2;
}
}
}
#ENJOY CODING
Post a Comment
FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP