import java.io.*;
class fib extends Thread
{
public void run()
{
try
{
int a=0,b=1,c=0;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the Limit");
int n=Integer.parseInt(br.readLine());
System.out.println("Fibonacci series:");
while(n>0)
{
System.out.println(c);
a=b;
b=c;
c=a+b;
n=n-1;
}
}
catch(Exception e)
{
}
}
}
class rev extends Thread
{
public void run()
{
try
{
System.out.println("Reverse is");
for(int i=20;i>=1;i--)
System.out.println(i);
}
catch(Exception e)
{
}
}
}
class s16
{
public static void main(String args[])
{
try
{
fib t1=new fib();
t1.start();
t1.sleep(5000);
rev t2=new rev();
t2.start();
}
catch(Exception e)
{
}
}
}
output:-
D:\5242>javac s16.java
D:\5242>java s16
Enter the Limit
2
Fibonacci series:
0
1
Reverse is
20
19
18
17
16
15
14
13
12
11
10
9
8
7
6
5
4
3
2
1
No comments:
Post a Comment