I am working on a linear system solver and I would like the user to be able to input the whole equation in one go as oppose to separately inputting each number.
I have tried to split the string at the "+" and "=" (The equation format is (ax+by=c)) but it is splitting the second part after the plus as "by=c" rather than just "by".
Here is my code:
System.out.print("Enter Your First Equation (ax + by = c): " );
String eq1 = sc.nextLine();
String[] part = eq1.split("\\+");
String[] part2 = eq1.split("\\=");
String result = part[0];
String result2 = part[1];
String result3 = part2[1];
double a1 = Double.parseDouble(result);
double b1 = Double.parseDouble(result2);
double c1 = Double.parseDouble(result3);
System.out.print("Enter Your Second Equation (ax + by = c): " );
String eq2 = sc.nextLine();
String[] part3 = eq1.split("\\+");
String[] part4 = eq1.split("\\=");
String result4 = part3[0];
String result5 = part3[1];
String result6 = part4[1];
double a2 = Double.parseDouble(result4);
double b2 = Double.parseDouble(result5);
double c2 = Double.parseDouble(result6);
System.out.println("Your Equations Are (1) " + a1 + "x + " + b1 + "y = " + c1);
System.out.println(" (2) " + a2 + "x + " + b2 + "y = " + c2);