Java Program to
generate the Fibonacci series of a given number:
//Input
Number: 7
// Output
- 1 1 2 3 5 8 13
class Fibonacci{
public
static void main(String args[]){
int
number =
Integer.parseInt(args[0]);
//taking no. as command line argument.
System.out.println("*****Fibonacci
Series*****");
int
a, b=0, c=1;
for(int
i=1;i<=num;i++){
System.out.print("
"+c+" ");
a
= b;
b
= c;
c = a+b;
}
}
}
No comments:
Post a Comment