0

string 1+2^3

in java, I want to get a string from the user and calculate string and show the result without Stack.(ex : 1+2*3 get from user and calculate with java program and print answer: 9) How can I do it?

12th Dec 2016, 12:20 PM
Amir Jafari
Amir Jafari - avatar
4 Answers
0
First of all string is a text. You cannot use text to calculate. What you probably ask here is how to get input from user as a bunch of variables and use those in formula. To get input you can use Scanner for example. For mathematics use Math. You can easily google those or find them in Java documents
12th Dec 2016, 12:15 PM
Andrey Kitsa
Andrey Kitsa - avatar
0
I know how to use scanner and math class. I want to do this for example: 1+2+3-4*5*.......
12th Dec 2016, 12:22 PM
Amir Jafari
Amir Jafari - avatar
12th Dec 2016, 1:00 PM
Amir Jafari
Amir Jafari - avatar
0
As others say: get input from user, explode string and do the math. That's all. Order of operations will be tricky.
7th Jan 2017, 1:37 AM
RadosƂaw Roszkowski
RadosƂaw Roszkowski - avatar