Solution Review: Calculating the first 'n' Fibonacci numbers
In this review, the solution of the challenge '' Calculating the First 'n' Fibonacci Numbers" from the previous lesson is provided.
We'll cover the following...
We'll cover the following...
Solution #
Press + to interact
Java
class HelloWorld {public static void main( String args[] ) {String fib = "";int n = 6;int first = 0, second = 1, fibonacci = 0;System.out.println("Fibonacci Series upto " + n + " Terms ");for (int c = 0; c < n; c++) {if (c <= 1) {fibonacci = c;fib += String.valueOf(fibonacci) + " ";} else {fibonacci = first + second;first = second;second = fibonacci;fib += String.valueOf(fibonacci) + " ";}System.out.println(fibonacci + " ");}}}
Explanation
...