title: Java program to extract coefficents from quadratic equation
body: <p>Problem: Java program to split the coefficients from a quadratic equation eg 
  if input string is:</p>
  
  <pre><code>String str1;
  str1 = "4x2-4x-42=0"
  </code></pre>
  
  <p>So I need to split the coefficients from the given input string and to get output as</p>
  
  <pre><code>a = 4 b = -4 c = -42
  </code></pre>
  
  <p>I tried this:</p>
  
  <pre><code>String equation = "ax2+bx-c=0";
  String[] parts = equation.split("\\+|-|=");
  for (int i = 0; i &lt; parts.length - 2; i++) {
      String part = parts[i].toLowerCase();
      System.out.println(part.substring(0, part.indexOf("x")));
  }
  System.out.println(parts[2]);
  </code></pre>
  
  <p>But I got the output as 23x2 and 4x and 4.
  Actual output needed is <code>23 ,- 4 , 4</code>.</p>