1
I have a question, can I convert a char or string variable into a mathematical operator? Is it possible? The language I use is Java.
For example:
int n1 = 1, n2 = 1;
char simb = '+';
int resultado = 1 simb 1.
resutado = 2;
1
I have a question, can I convert a char or string variable into a mathematical operator? Is it possible? The language I use is Java.
For example:
int n1 = 1, n2 = 1;
char simb = '+';
int resultado = 1 simb 1.
resutado = 2;
Browser other questions tagged java operators
You are not signed in. Login or sign up in order to post.
It’s not much I want, no
– Christian Gomes da Silva
It doesn’t run away from duplicate responses much, unless you make a "nut" solution that would be to analyze each character and detect the symbols with
switch...case
.– user28595
Then explain the question better, because you said "convert a char or string variable into a mathematical operator" and it seems to me exactly that, if it’s something else it would be better to explain exactly, or maybe you didn’t understand the answers. Note that there are 3 different answers, look at the 3 carefully.
– Guilherme Nascimento
Okay, I’ll see you again, thanks!
– Christian Gomes da Silva
Guys I’m sorry but I don’t understand how you do, I’m still new in programming, could give me an example, without leaving programming "nut"?
– Christian Gomes da Silva
@Christiangomesdasilva Explain better what you want to do. Why you want to use a string as a mathematical operator?
– Victor Stafusa
So @Victorstafusa I’m developing an app that contains 3 levels of difficulty and 3 activities for each level, and this app contemplates the 4 basic mathematical operations. There to not have to do 3 activitys for each operation and other 3 layouts, I would like to use the same three activitys that I already did, and with the character I could change the symbols of the operations, so I wanted to know how to make a string or char that has the symbol of the operation, to trade in operations.
– Christian Gomes da Silva
That is, you had an X problem, but you asked a question about a completely different Y problem. See more about this here. The proper solution goes far beyond what you asked. I suggest posting a new question reset from scratch.
– Victor Stafusa
Okay, thank you so much for the advice, I’ll rephrase a new question from scratch and post, and once again it was worth!
– Christian Gomes da Silva