Difference between revisions of "Fibonacci Numbers"

From CompSciWiki
Jump to: navigation, search
Line 1: Line 1:
 
{{1010PrAD|ProblemName=Fibonacci Numbers
 
{{1010PrAD|ProblemName=Fibonacci Numbers
  
|Problem= This problem involves you writing a program that will take in which Fibonacci number you want to print out and then iteratively calculates the number. Remember that the algorithm for Fibonacci numbers is Fibonacci[n] = Fibonacci[n-1] + Fibonacci[n-2] where Fibonacci[0] = 0 and Fibonacci[1] = 1. Remember you are going to want to declare your array but not specify the size until you take in your input with JOptionPane. Print out the number that is specified.  
+
|Problem= This problem involves you writing a program that will take in which Fibonacci number you want to print out and then iteratively calculates the number. Remember that the algorithm for Fibonacci numbers is Fibonacci[n] = Fibonacci[n-1] + Fibonacci[n-2] where Fibonacci[0] = 0 and Fibonacci[1] = 1. Remember you are going to want to declare your array but not specify the size until you take in your input with JOptionPane: <pre>JOptionPane.showInputDialog()</pre>
 +
Remember that you can convert Strings that are numbers to ints using:<pre>Integer.parseInt()</pre>
 +
Print out the number that is specified to the console with: <pre>System.out.println();</pre>
  
  

Revision as of 09:56, 8 April 2010

Back to the Program-A-Day homepage

Problem

This problem involves you writing a program that will take in which Fibonacci number you want to print out and then iteratively calculates the number. Remember that the algorithm for Fibonacci numbers is Fibonacci[n] = Fibonacci[n-1] + Fibonacci[n-2] where Fibonacci[0] = 0 and Fibonacci[1] = 1. Remember you are going to want to declare your array but not specify the size until you take in your input with JOptionPane:
JOptionPane.showInputDialog()
Remember that you can convert Strings that are numbers to ints using:
Integer.parseInt()
Print out the number that is specified to the console with:
System.out.println();
 

Introducing Arrays

Wiki array01.jpg

Solution

The solution...

Code

Solution Code

Back to the Program-A-Day homepage