Output:
Source Code:
import java.io.*;
public class Fibonacci {
private static PrintStream p=System.out;
public static BufferedReader q=new BufferedReader (new InputStreamReader (System.in));
public static void main(String []args)throws IOException{
String ans;
do{
p.print("Enter Limit: ");
int n=Integer.parseInt(q.readLine());
int x=1, y=1, z;
p.print(x +" "+y +" ");
for (int i=0; i
z=y+x;
if (z<=n){
p.print(z +" ");
x=y;
y=z;
}
}
p.println();
p.println("Try again?[y/n]: ");
ans=q.readLine();
}
while(ans.charAt(0)=='Y' || ans.charAt(0)=='y');
}
}
0 comments:
Post a Comment