You are here: Home / Topics / Program to Print Lucas series in Java

Program to Print Lucas series in Java

Filed under: Java on 2023-08-18 06:46:47

// Program to Print the Lucas Series.
//  1  1  1  3  5  9.....n  Terms.

class  LucasTest 
{
public static void main( String args[ ] )
{
 int n, i , a = 1, b = 1, c = 1, d;
  
 n = 10;

 System.out.print( " " + a + " " + b + " " + c);   
 for( i=1 ; i<=(n-3) ; i++ )
    {
  d = a + b + c;
  System.out.print( " " + d );
  a = b;
  b = c;
  c = d; 
    }
   }
}


Output:

1  1  1  3  5  9  17  31  57  105

About Author:
Y
Yatendra Sir     View Profile
Hi, I am using MCQ Buddy. I love to share content on this website.