java.util.regex.PatternSyntaxException: Dangling meta character '+' near index 0 +

前端 未结 5 1224
旧时难觅i
旧时难觅i 2020-12-15 15:54

I am getting the error when I launch my UI that causes this code to spit the error at me in the title. It works for all of my other operator symbols so I am really not sure

5条回答
  •  轮回少年
    2020-12-15 16:24

    Change: String[] split = nums.split(operator);

    To this: String[] split = nums.split("\\" + operator);

    edit: This will only work for standard operators, not the x or X. You'll have to change your String[] operators declaration actually, like the other answer mentioned. Personally though, I'd do some kind of input validation and do a replace() on x or X to be * instead

提交回复
热议问题