How do you turn a character into a mathematical symbol?

Asked

Viewed 72 times

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;
  • It’s not much I want, no

  • 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.

  • 2

    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.

  • Okay, I’ll see you again, thanks!

  • 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"?

  • @Christiangomesdasilva Explain better what you want to do. Why you want to use a string as a mathematical operator?

  • 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.

  • 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.

  • Okay, thank you so much for the advice, I’ll rephrase a new question from scratch and post, and once again it was worth!

Show 4 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.