There is something that I want to know. I have homework where they want us to take two string input in polynomial form, and there is lots of implementation. Here my question: when I take the input from the user, I can split the string into polynomial parts but it goes wrong:
The string: "-x^3 - 6x^2 + 4x + 22"
I want to split this like:
-x^3
- 6x^2
+ 4x
+ 22
but it prints
package splitmethod;
import java.util.Scanner;
import java.io.*;
public class uygulama {
public static void main(String args[]){
System.out.println("lütfen parçalmak istidigniz polinomu girniz ");
Scanner input= new Scanner(System.in);
String polinom= input.nextLine();
String[] result;
System.out.println("");
result=polinom.replaceAll("\\s+","").split("(?<=[+-])");
for(int i=0;i<result.length;i++){
System.out.println(result[i]);