title: Java Using the return value of a loop within the loop
body: <p>sorry but english is nut my first language. I'm building a main class and method to create a bunch of random numbers. I want to use a  for-loop and want to use with every step of the loop the result of the last loop. </p>
  
  <p>The User is asked to enter 3 integers to create a random number with the formula: 
  z =  (a*z+b)%m;</p>
  
  <p>1.Step
  z = (a*0+b)%m;  Lets say the result is 7.
  2. Step:
  z= (a*7+b)%m
  and so on.</p>
  
  <p>I want the program to give me 20 random numbers.
  In the first step of the loop the random number z is 0, and then with every additional step the random number is built from the result of the last step.
  I hope you guys understand what I'm trying to say. </p>
  
  <p>My Code so far:</p>
  
  <pre><code>import java.io.*;
  public class Zufallszahlentest {
  
      public static void main (String [] args) throws IOException {
  
          BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
          System.out.println("Geben Sie nacheinander die Werte für a,b &amp;m ein.");
          int a = Integer.parseInt(in.readLine());
          int b = Integer.parseInt(in.readLine());
          int m = Integer.parseInt(in.readLine());
  
          Methode(a,b,m);
          System.out.println(Methode(a,b,m));
      }
  
      static int Methode(int a, int b, int m){
              int z = 0;
              for (int i = 0; i &lt;= 20; i++) {
                   z = (a*z+b)%m;
              }
              return z;
       }
  }
  </code></pre>
  
  <p>I've been sitting on this for hours, I've built huge loops with no result and I feel like getting dumber and dumber with every try. </p>
  
  <p>Help would be highly appreciated.</p>