Arithmetic sequence with increasing difference || part 5 || Java programs || Java
In this, we are going to write a  program to print the 1, 2, 5, 12, 29, 70, … up to n in series in Java.


import java.util.*;

class Series11
{
    public static void main(String[] args) 
    {
        int i, n, f = 1, s = 0, t;
        Scanner sc = new Scanner(System.in);
        System.out.print("Enter the number of terms:");
        n = sc.nextInt();
        for (i = 1; i <= n; i++) 
        {
            t = f + 2 * s;
            System.out.print(t + " ");
            f = s;
            s = t;
        }
    }
}
#ENJOY CODING

Post a Comment

FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP

Previous Post Next Post