我想在数学运算符之后和之前放置空格:
例如:
55/2 * 456-5 + 5
结果: 55/2 * 456 - 5 + 5
答案 0 :(得分:0)
一种方法:
String lEquation = "55/2*456-5+5";
lEquation = lEquation.replaceAll("\\/"," \\/ ").replaceAll("\\*"," \\* ").replaceAll("-"," - ").replaceAll("\\+"," \\+ ");
System.out.println("My equation: "+ lEquation);
结果将是:
My equation: 55 / 2 * 456 - 5 + 5