开发者

Calculator app for Android

I'm thinking about an algorithm for building a calculator. My first idea was to do an array and after click some button save the value of pressed button to this array. And after click the button "=" I would walked this array via cycle for (for example) and from entered value I will make up the expression - for example: 1.iteration - "5" 2.iteration - "5" 3.iteration - "+" 4.iteration - "8" END OF ARRAY

So the result expression will be: 55+8

But I'm not sure, if this idea is right - I think i开发者_如何学Got's a bit complication -- exist some pretty way, how to do?

Thanks


I would tokenize the string and build an abstract syntax tree which you could then walk to evaluate the children


dont use an array.. just use variables its enough. have one text box just type in the text box say(55). after you pressed any operators(+,-,*,/) just store that(55) in A variable. after that you enter 8. add that 8 to the 55.. use two variables.. any doubt means pls communicate with me

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜