Program To Print a Numbers from Fibonacci Series
class FibonacciSeries // By Steve
{
public static void main (int a)
{
int x=0,y=1;
int d=0;
System.out.print(x+",");
System.out.print(y+",");
for(int i=1;i<=a;i++)
{
d=x+y;
System.out.print(d+",");
x=y;
y=d;
}
}
}
Input: 14
Output:
nice program
ReplyDeleteCan you explain me this:
ReplyDeleteThe variable "i" is not declared in the program...but still,
there is this statement- "for(int i=1;i<=a;i++)"
How does this program work?
'i' is declared itself in the for statement
Deletei.e for(*int* i=1;i<=a;i++)
i is in the parameter part....
Deleteint i is declared in the for loop.
Deletethe 'int' keyword does the trick.
int i is declared in the for loop.
Deletethe 'int' keyword does the trick.
It is not declared in Program...But is declared in for loop statement
Delete'i' is declared itself in the for statement
ReplyDeletei.e for(*int* i=1;i<=a;i++)
really good program
ReplyDeletereally good program
ReplyDelete47 doesn't work, how do you fix overflow
ReplyDeleteUse try{} block to fix the overflow exceptions
DeleteThanx
ReplyDeleteThanks
ReplyDelete