Computer Science, asked by selvisri1811998, 1 year ago

1,2,1,3,2,5,3,7, this series is a mixture of two series all the the odd terms in this series form a fibonacci series and all the the even erms form the prime numbers in ascending order.write a program o find nth term in the series.

Answers

Answered by nitish8089
0

code..........
import java.util.Scanner;
class Series1
{
public static int oddSeries(int x){
int y;
if(x==1||x==3){
return 1;
}
else{
y=oddSeries(x-4)+oddSeries(x-2);
}
return y;
}
public static int evenSeries(int x){
int a=0;
int n=2;
int k=0;
do{
int count=0;
for(int i=2;i<=n;i++){
if(n%i==0){++count;}
}
if(count==1){
a=n;
n++;
k++;}
else{
n++;}
}while(k<(x/2));

return a;
}
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("enter the nth digit whose value you want ");
int n=sc.nextInt();
if(n>0){
if(n%2==1){
int z=Series1.oddSeries(n);
System.out.println(z);
}
else{
int b=Series1.evenSeries(n);
System.out.println(b);
}

}
else{
System.out.println("invalid input");
}
}
}
Similar questions