Difference between revisions of "Fibonacci sequence"
From CompSciWiki
Line 14: | Line 14: | ||
<br/> | <br/> | ||
You may assume that the user always enters correct intenger format.<br/> | You may assume that the user always enters correct intenger format.<br/> | ||
+ | |||
+ | |SideSectionTitle=...by students | ||
+ | |||
+ | |SideSection= | ||
+ | [[Image:OperatingSystemExample.jpg|float|267px]] | ||
+ | <BR> | ||
+ | Taken from http://www.flickr.com/photos/daniello/565304023/ | ||
+ | |||
+ | An image or By Students section | ||
|SolutionCode=<pre> | |SolutionCode=<pre> | ||
Line 37: | Line 46: | ||
} | } | ||
}</pre> | }</pre> | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
|Solution=<pre> | |Solution=<pre> | ||
Line 54: | Line 54: | ||
Then, the next step would be declaring variables; in this program we will need only two int variables. | Then, the next step would be declaring variables; in this program we will need only two int variables. | ||
current will be F(n) and previous will be F(n-1). Do NOT forget to declare them outside the for loop. | current will be F(n) and previous will be F(n-1). Do NOT forget to declare them outside the for loop. | ||
+ | </pre> | ||
}} | }} |
Revision as of 23:31, 1 April 2010
Back to the Program-A-Day homepage
ProblemWrite a complete Java program Fibonacci that:
|
...by students
An image or By Students section | |
---|---|---|
SolutionIn order to get the user input by JOptionPane, you will first have to import the swing package. You can import swing package by import javax.swing.*; or import javax.swing.JOptionPane; Then, the next step would be declaring variables; in this program we will need only two int variables. current will be F(n) and previous will be F(n-1). Do NOT forget to declare them outside the for loop. | ||
Code |