title: How do you use conditions in lambda expression in java 8?
body: <p>I am beginner in programming and I was wondering how you can write lambda expressions with conditions.</p>
  
  <pre><code>public interface MathInterface {
  
      public int retValue(int x);
  
  }
  
  public class k1{
  public static void main(String [] args) {
  MathInterface f1 = (int x) -&gt; x + 4; // this is a normal lambda expression
      }
  }
  </code></pre>
  
  <p>The code above should represent the mathematical function: </p>
  
  <p>f(x) = x + 4.</p>
  
  <p>So my question is how can i write a lambda expression that covers this function:</p>
  
  <p>f(x) = </p>
  
  <p>x/2 (if x is divisble by 2)</p>
  
  <p>((x + 1)/2) (otherwise)</p>
  
  <p>any help appreciated :)</p>
  
  <p>Edit: The answer from @T.J. Crowder was, what I was searching.</p>
  
  <blockquote>
    <p>MathInteface f1 = (int x) -> (x % 2 == 0) ? x / 2 : (x + 1) / 2;</p>
  </blockquote>