Thursday, 11 August 2016

Fibonacci Series Prime numbers in java


class fibo extends Thread
{
int f=0,s=1,next;
public void run()
{
System.out.println("fibo of "+f+"\n"+s);
for(int i=2;i<20;i++)
{
next=f+s;
f=s;
s=next;
System.out.println("fibo of "+next);
}
}
}
class prime extends Thread
{
int i,j,flag=0;
public void run()
{
try
{
sleep(5000);
}
catch(Exception e){}
for(i=1;i<=20;i++)
{
flag=0;
for(j=1;j<=i;j++)
{
if(i%j==0)
{
flag++;
}
}
if(flag==2)
System.out.println("prime no:"+i);
}
}
}
class fibprim
{
public static void main(String args[])
{
fibo t1=new fibo();
prime t2=new prime();
t1.start();
t1.setPriority(10);
t2.start();
t2.setPriority(3);
}
}

No comments: