Saturday, February 14, 2015

Java program to print fibonacci series

Java program to print fibonacci series

class Fibonacci
{
public static void main(String...s)
{
int first=0,second=1,third,n,i;
n=Integer.parseInt(s[0]);

System.out.print("
"+first+" "+second);

for(i=2;i<n;i++)
{
third=first+second;
first=second;
second=third;
System.out.print(" "+third);
}
System.out.println();
}
}

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.