class
fibnumbers
{
public
static void main(String args[])
{
int
no=Integer.parseInt(args[0]);
int
a=0,b=1,sum;
int
n=1;
System.out.println("Fibonacci
numbers: ");
System.out.print(a+","+b);
do
{
sum=a+b;
System.out.print(","+sum);
a=b;
b=sum;
n++;
}while(n<=no);
}
}
Output:
D:\JavaPrograms\CmdPrograms>javac fibnumbers.java
D:\JavaPrograms\CmdPrograms>java fibnumbers 10
Fibonacci
numbers:
0,1,1,2,3,5,8,13,21,34,55,89
0 Comments
Post a Comment