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