So I have this code which prints the lucas series.
Lucas series is a series which starts from 2 and 1 and the following numbers are the sum of the previous 2 number like
2
1
2 +1 = 3
3 +1 = 4
4 +3 = 7
and so on.
import java.util.*;
public class Main
{
public static void main(String[] args) {
int a=2,b=1,c,i;
Scanner sc=new Scanner(System.in);
System.out.println("Enter the length of lucas series:");
int len=sc.nextInt();
for(i=1;i<=len;i++){
c=a+b;
System.out.print(c+" ");
a=b;
b=c;
}
}
}
So the problem is if I for example say input 10 for the scanner input. Then it starts from 3, 4, 7, etc. So how do I get the first 2 and 1? I need it to print all 10 starting from 2 and 1.
So that is 2,1,3,4,7....