import java.io.*;
import java.lang.*;
class Fib extends Thread
{
int n;
Fib(int n)
{
this.n=n;
}
public void run()
{
int prev, next, sum, i;
prev=next=1;
//System.out.println("Fib Nos:");
for(i=1;i<=n;i++)
{
System.out.println("Fib no:"+prev);
sum=prev+next;
prev=next;
next=sum;
}
}
}//Fib class close
class Even extends Thread
{
int n;
Even(int n)
{
this.n=n;
}
public void run()
{
int num;
//System.out.println("Even Nos:");
num=2;
while( num<=n)
{
System.out.println("Even no:"+num);
num = num + 2;
}
}
}//Even class close
class Odd extends Thread
{
int n;
Odd(int n)
{
this.n=n;
}
public void run()
{
//System.out.println("Odd Nos:");
for(int i=1;i<=n;i++)
{
if(i%2!=0)
System.out.println("Odd no:"+i);
}
}
}//Even class close
class FibNum2
{
public static void main(String args[])
{
try
{
int n;
DataInputStream in=new DataInputStream(System.in);
System.out.println("Enter the limit:");
n=Integer.parseInt(in.readLine());
Fib ob1=new Fib(n);
Even ob2=new Even(n);
Odd ob3=new Odd(n);
ob1.start();
//ob2.sleep(500);
ob2.start();
//ob3.sleep(500);
ob3.start();
}
catch (Exception e)
{
}
}
}
import java.lang.*;
class Fib extends Thread
{
int n;
Fib(int n)
{
this.n=n;
}
public void run()
{
int prev, next, sum, i;
prev=next=1;
//System.out.println("Fib Nos:");
for(i=1;i<=n;i++)
{
System.out.println("Fib no:"+prev);
sum=prev+next;
prev=next;
next=sum;
}
}
}//Fib class close
class Even extends Thread
{
int n;
Even(int n)
{
this.n=n;
}
public void run()
{
int num;
//System.out.println("Even Nos:");
num=2;
while( num<=n)
{
System.out.println("Even no:"+num);
num = num + 2;
}
}
}//Even class close
class Odd extends Thread
{
int n;
Odd(int n)
{
this.n=n;
}
public void run()
{
//System.out.println("Odd Nos:");
for(int i=1;i<=n;i++)
{
if(i%2!=0)
System.out.println("Odd no:"+i);
}
}
}//Even class close
class FibNum2
{
public static void main(String args[])
{
try
{
int n;
DataInputStream in=new DataInputStream(System.in);
System.out.println("Enter the limit:");
n=Integer.parseInt(in.readLine());
Fib ob1=new Fib(n);
Even ob2=new Even(n);
Odd ob3=new Odd(n);
ob1.start();
//ob2.sleep(500);
ob2.start();
//ob3.sleep(500);
ob3.start();
}
catch (Exception e)
{
}
}
}
No comments :
Post a Comment