Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;//java package
- class fibo
- {//class starts
- void fib(int n,int m)// method fib
- {
- int f1=0,f2=1,f3=1;
- if(n==0 ){
- System.out.print("0 ,1,");
- }
- while(f1<=m){
- f1=f2;
- f2=f3;
- if(f3>=n && f3<=m){
- System.out.print(f3+",");}
- f3=f1+f2;
- }
- }
- public static void main(String args[])//main method
- {
- Scanner in= new Scanner(System.in);
- fibo fi=new fibo();
- int lb,ub;
- System.out.println("enter the lower and upper bound: ");
- lb=in.nextInt();ub=in.nextInt();
- System.out.println("the fibonacci numbers in the range "+lb+" - "+ub+" are:");
- fi.fib(lb,ub);
- }
- }// class ends
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement