THE NEW ERA ZONE
Would you like to react to this message? Create an account in a few clicks or log in to continue.

JAVA BASICS (FIBONACCI SERIES)

Go down

JAVA BASICS (FIBONACCI SERIES) Empty JAVA BASICS (FIBONACCI SERIES)

Post by djay03 Sun Apr 13, 2014 1:38 am

Logic: Sum of previous two numbers will give us next number.


public class Fibonacci
{
public static void main(String args[])
{
int prev, next, sum, n;
prev=next=1
for(n=1;n<=10;n++)
{
System.out.println(prev);
sum=prev+next;
prev=next;
next=sum;
}
}
}



OUT PUT
_________________________________________

1
1
2
3
5
8
13
...
djay03
djay03

Posts : 23
Points : 61
Join date : 2014-04-01
Age : 31

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum