Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using +-*/ etc. in char

Status
Not open for further replies.

PerD

Programmer
May 4, 2000
12
SE
Hi

Is it possible to use an operator (ex: +) stored in a char when calculating an expression?

ie: 1 '+' 2

 
no we can't used this char '+' for operation to perform this for addition but if still you want to add then
switch(operator){
case '+':
return a+b;
break;
case '*':
return a*b;
break;
...

default:
break;
}

thus u can add but not directly
 
Well, the switch statement is exactoy what I wanted to skip. And as I was told that javascript could to it, I thoght that Java should be able to too. Oh well..

/Regards Per
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top