Series

6. Program

6. How to Print this series ? 1, 5, 3, 9, 17, 29, 55, 101, 185....N

import java.util.Scanner; class Series5 { public static void main(String args[]) { Scanner sc = new Scanner(System.in); System.out.println("Enter the upper limit of N"); int n = sc.nextInt(); int a = 1 ,b =5, c = 3, temp; while(a <= n) { System.out.print(a + " "); temp = a+b+c; a = b; b = c; c = temp; } } }