Series

8. Program

8. How to Print this series ? 1, 1, 2, 12, 14, 26, 40, 264, 304, 568.....N

import java.util.Scanner; class Series3 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("Enter the digit till you want the Series"); int no = sc.nextInt(); int j = 1; int a[] = new int[no]; a[0] = 1; a[1] = 1; for(int i = 2;i < no ; i++) { if(i == 4*j-1) { a[i] = 4*(a[i-1] + a[i-2]); j++; } else if(i%4 != 0) { a[i] = a[i-1] + a[i-2]; } else if(i%4==0) { a[i] = a[i-1] + a[i-2]; } } for(int p = 0 ; p < a.length; p++) { System.out.print(a[p]+", "); } } }