public class FibMethod
{
void fib()
{
int a=0,b=1,c;
System.out.print("\n"+ a +" "+ b);
for(int i=0; i<5; i++)
{
c=a+b;
a=b;
b=c;
System.out.print(" " + c);
}
}
public static void main(String[] args)
{
FibMethod obj = new FibMethod();
obj.fib();
}
}
Output:
0 1 1 2 3 5 8
Basic Java programs. All programs done in very simple ways. It helps beginners to grow their programming skills and build a programming logic.
Monday, 7 December 2020
Fibonacci Series using Method
Subscribe to:
Post Comments (Atom)

No comments:
Post a Comment
If you have any doubts, please let me know