Java calculator | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Java calculator

Hello im new in java.i need a method for my calculator to make more than 2 action.not just firstnumber+secondnumber?please help me!thnx

10th Apr 2019, 6:27 AM
Aldo Çipi
Aldo Çipi - avatar
3 Answers
+ 1
You could solve this by recursion. Or iterate over all actions you wanna take. Also some more advanced topics for a calculator would be to look into reverse polish notation.
10th Apr 2019, 6:58 AM
Dragonxiv
Dragonxiv - avatar
+ 1
You can pass the expression as a whole string then split it to an array, then perform the operation depending on the operator using a switch statement .. For example you pass "3 * 2", when you split it it's "3", "*", "2", arr[1] is "*", so you perform multiplication.
10th Apr 2019, 7:05 AM
Afnan A.
Afnan A. - avatar
28th Feb 2020, 9:37 PM
Jegors Čemisovs
Jegors Čemisovs - avatar