title: How to solve a 2 variable linear simultaneous equation? Java
body: <p>Say you have  </p>
  
  <pre><code>3x + 2y = 11 
  2x - 3y = 16  
  </code></pre>
  
  <p>How would you work out <code>x and y</code> in Java?</p>
  
  <p>After doing some algebra I figured out that <code>x = de-bf / ad-bc</code> and <code>y = af-ce / ad-bc</code>  </p>
  
  <p>These show what the letters are
  <code>a + b = e</code> and <code>c + d = f</code> </p>
  
  <p>Whenever I write the code it always gives me the wrong answer, I am not sure if that is due to using int instead of doubles or what. Would it also be possible to parse the letters from the equation e.g</p>
  
  <pre><code>input: 5x - 3y = 5
  parased as: a = 5, b = -3 and e = 5
  </code></pre>
  
  <p>Here is the code without parsing</p>
  
  <pre><code>public static void solveSimultaneousEquations(double a, double b, double c, double d, double e, double f) {
      double det = 1/ ((a) * (d) - (b) * (c));
      double x = ((d) * (e) - (b) * (f)) / det;
      double y = ((a) * (f) - (c) * (e)) / det;
      System.out.print("x=" + x + " y=" + y);
  }
  </code></pre>