Lucas Series in JAVA
Lucas Series
Lucas Series : A series of numbers in which each number (Lucas Number) is the sum of the two preceding numbers. It starts from 2 and 1.
It is similar to Fibonacci Series
The first few terms of the sequence are :-
Program to Print Lucas Series given below :-
Program :-
import java.io.*;
import java.util.*;
class Lucas_Series
{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
int a=2,b=1,c=0,n,i;
System.out.println("Enter No. of terms");
n= in.nextInt();
System.out.println("Lucas Series given below:-");
System.out.print(a+"\t");//printing first number
System.out.print(b+"\t");//printing second number
for(i=3;i<=n;i++)
{
c=a+b;
System.out.print(c+"\t");
a=b;
b=c;
}
}//end of main method
}//end of class
import java.util.*;
class Lucas_Series
{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
int a=2,b=1,c=0,n,i;
System.out.println("Enter No. of terms");
n= in.nextInt();
System.out.println("Lucas Series given below:-");
System.out.print(a+"\t");//printing first number
System.out.print(b+"\t");//printing second number
for(i=3;i<=n;i++)
{
c=a+b;
System.out.print(c+"\t");
a=b;
b=c;
}
}//end of main method
}//end of class
For Proper Understanding Watch the Video :-
Watch this video : Lucas Series
Follow me on Instagram
All the best :)
Keep Learning :)
Comments
Post a Comment