+ 4
This java code of mine was downvoted. Can someone see what was wrong with it?
This code of mine: https://code.sololearn.com/c6onX1jZFliG/#java was downvoted, and I was curious if there was something wrong with the code. After checking multiple times, I made sure that it worked (and checked it with a java programmer, too), but considering that it was downvoted, I would think there's be something wrong with it.
3 ответов
+ 4
Hi Sheldon,
I had a look at your code. I don't know java yet, but I think I can say that there must be a better solution than your long long switch.
Actually what you're doing here is asking your code to evaluate a mathematical expression. Thing is : your language already natively knows how to do it. That makes it quite useless to separate it into cases.
Your code is doing something like :
if input is "a + b"
then output is (a+b)
if input is "a * b"
then output is (a*b)
etc ...
I tryed "3 + 2 * 4" and your code is lost.
The solution would be :
if in put is "math expression with syntax rules"
then output is (this same expression whatever it is)
from which you may add some special replacements, shorter syntaxes, or exceptions (syntax error detection).
I hope it helps you,
keep coding : )
+ 3
Some people are just jerks and downvote but when I tried it I always got a error to put spaces between stuff
+ 3
@Cestpasgrave - That does make sense, I suppose.
I will probably think about creating a 2.0.0 version of this calculator, where more leeway is given. I did always not like my calculator only being able to put in 2 numbers at a time, though I never thought spaces was a problem.
After all, this calculator was made for practice so I can improve in the future by making better versions.