Fibonacci Series using Java.
class FibonacciSeries
{
public static void main(String args[])
{
int PrevNum, NextNum, Sum, i;
PrevNum=NextNum=1;
System.out.println();
for(i=1;i<=10;i++)
{
System.out.print(PrevNum+" ");
Sum=PrevNum+NextNum;
PrevNum=NextNum;
NextNum=Sum;
}
}
}
{
public static void main(String args[])
{
int PrevNum, NextNum, Sum, i;
PrevNum=NextNum=1;
System.out.println();
for(i=1;i<=10;i++)
{
System.out.print(PrevNum+" ");
Sum=PrevNum+NextNum;
PrevNum=NextNum;
NextNum=Sum;
}
}
}
- Save the file with name FibonacciSeries.java
- Compile with: javac FibonacciSeries.java
- Run with: java FibonacciSeries
No comments:
Post a Comment