0

How do I solve a math problem that is in a string? The user will enter a math problem that starts with the word calculate. like "calculate 5 + 2" or "calculate 10 - 3" and the program needs to solve it.

So far I have the user ask a question and then if (question.toLowerCase().contains("calculate")). Now I need it to solve but idk what to do.

Jen
  • 1
  • 1
  • Parse the input `String` to separate the "calculate", "5", "+", and "2". Make sure there are four tokens, the first is "calculate", the second and fourth tokens are integers, and the third token is a plus or minus. – Gilbert Le Blanc Apr 21 '23 at 02:51
  • Welcome to Stack Overflow. This has been treated a lot, not only on Stack Overflow but on many websites. Use your search engine. And BTW, you are supposed to do that every time before posting a question here. See you around. – Ole V.V. Apr 21 '23 at 03:00
  • I am new to coding. I having been searching websites for two hours and have not found a solution. This is the last part of the program I have to finish and I’m stumped. I also reached out to classmate who also can’t figure it out and Reddit with no response. – Jen Apr 21 '23 at 03:11
  • I understand. I am sorry, Stack Overflow does not work for tutoring the basics of programming. I hope you will be able to find help some place else. For a decent Stack Overflow question you would at the least need to tell us what your search had brought up and spell out in what way it did not help or was insufficient. Until proven otherwise I still believe this has already been covered in depth elsewhere. – Ole V.V. Apr 21 '23 at 03:58

0 Answers0