title: How can I return the FIbonacci sequence using an int return type method without using recursion?
body: <p>I'm trying to create a method in Java that prints the fib series up to the number passed to the method. My issue is that I'm required to use an <strong>int</strong> return type to return the series and I <strong>cannot use recursion</strong>.</p>
  <h1>My First Idea</h1>
  <p>My original idea was like shown. Which works just fine. It takes an argument of type <strong>int</strong> and returns <strong>void</strong> simply printing the numbers as they are calculated.</p>
  <pre class="lang-java prettyprint-override"><code>public void fibonacci(int num) {
      int a = 0;
      int b = 0;
      int c = 1;
        
  
      for (int i = 0; i &lt; num; i++) {
          a = b;
          b = c;
          c = a + b;
          System.out.print(c + &quot;, &quot;);
      }
  }
  </code></pre>
  <h1>What The Question Asks For</h1>
  <p>The code below shows what I was tasked to do. It asked for a method that takes an argument of type <strong>int</strong> and returns type <strong>int</strong>.</p>
  <pre class="lang-java prettyprint-override"><code>public int fibonacci(int num) {
     
      //some code...
  
      return x; //This is what confuses me. I know this isn't right.
  }
  </code></pre>
  <p>To me this just seems impractical and maybe even impossible to use an int return type. I'm wondering if anyone knows a way this is possible.</p>
  <p>Expected Output:</p>
  <pre class="lang-java prettyprint-override"><code>//Method call in driver class.
  fibonacci(5);
  
  //This would print to console.
  1, 1, 2, 3, 5
  </code></pre>