title: How to execute a statement within a recursive method only once in Java?
body: <p>I need to execute a statement within a recursive method only once in Java, without using any of the variables in the method parameters, without any external variables outside the method, and the statement must be inside the method.</p>
  
  <pre><code>public static boolean recursiveMethod(int x) {
      if (x &gt;= 5) {
          return true;
      }
      boolean isPrintedOnce = false;
      if (isPrintedOnce == false) {
          System.out.println("Printed once!"); // Print this statement only once
          isPrintedOnce = true;
      }
      return recursiveMethod(x + 1);
  }
  
  public static void main(String[] args) {
      System.out.println(recursiveMethod(0));
  }
  </code></pre>
  
  <p>This doesn't work because "boolean isPrintedOnce = false;" is executed five times so the conditional statement is useless. I get this as my output:</p>
  
  <pre><code>Printed once!
  Printed once!
  Printed once!
  Printed once!
  Printed once!
  true
  </code></pre>
  
  <p>EDIT: The requirements are that,
  1) can't use external variables outside of the method
  2) no use of variables in method parameters
  3) the statement must be inside the method
  (My assignment requires this. I might have read it wrong because it seems impossible with these requirements but I believe these are requirements in it.)</p>