title: Writing an if-statement inside of return
body: <p>I want to write a program in java that calculates the squareroot and I am not allowed to use the math module</p>
  
  <p>My code is </p>
  
  <pre><code>public class Quadratwurzel
  
  public static double quadratwurzel(double x, int n) {
  return(if (n == 0){x+1/2} else{0.5*quadratwurzel(x,n-1)+x/quadratwurzel(x,n-1)})}
  </code></pre>
  
  <p>I am hoping someone can explain me why I cannot write an if/else statment inside of return because in my lecture notes it says that we have to write a statement inside of return and the statment gets substituated with the parameters.</p>
  
  <p>I.e if I start the method or function </p>
  
  <pre><code>quadratwurzel(32.0,6)
  </code></pre>
  
  <p>Then the body of the function which is inside of return will be substituated with:</p>
  
  <pre><code>(32.0,6)
  </code></pre>
  
  <p>And because </p>
  
  <pre><code>6!=1,5!=1,...2!=1
  </code></pre>
  
  <p>The method would be started 5 times again recursively until it termintates.</p>
  
  <p>That is my idea and I was wondering why the substitution here does not work like that.</p>
  
  <p>I hope somebody can help and give me the correct code for the idea</p>