Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.

# Thread: Generate prime numbers within fiboncacci series?

1. ## Generate prime numbers within fiboncacci series?

Hey,

i am new to java programming,and i am working a simple program that generate prime numbers whithin the generated fibonacci series,i tryed a lot to track the error out,but its just not displaying me the prime number(though fibonnaci numbers are generated),hope this forum can help to track my error which is bugging me from the past 5-6 hours.(platform used is netbeans 6.9)

/* program to generate prime numbers within the fibonnaci numbers */

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package javaapplication5;
import java.lang.*;
import java.util.*;

public class Main
{
public static void main(String[] args)
{
int fib1,fib2,fib3,n=0,flag, int i;
int a[]=new int[20];
Scanner sc=new Scanner(System.in);
n=sc.nextInt();
fib1=0;
fib2=1;
System.out.println(fib1+ " " +fib2);
fib3=fib1+fib2;
while(fib3<n)

{
System.out.println(fib3);
fib3=fib1+fib2;
fib1=fib2;
fib2=fib3;

flag=1;

for(i=2;i<=fib3/2;i++)
{
if(fib3%i==0)
{
flag=0;

}
if(flag==1)
{
System.out.println("the prime numbers are");
System.out.println(i);
}

}

}

}
}

2. Code:
```import java.util.*;

public class Main{
public static void main(String[] args){
int fib1,fib2,fib3 = 0,n=0;
Scanner sc=new Scanner(System.in);
n=sc.nextInt();

fib1=-1;
fib2=1;

while(fib3<n){
System.out.print(fib3);

if(isPrime(fib3)){
System.out.print(" - Is Prime");
}
System.out.println("");

fib1=fib2;
fib2=fib3;
fib3=fib1+fib2;

}
}

public static boolean isPrime(int number){
for(int i = 2; i <= number / 2; ++i){
if (number % i == 0)
return false;
}
return true;

}

}```

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•