Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Why Can't Characters Be Converted to Operators at Runtime?

junho joJul 26 2024

While learning Java, I wondered if there was a way to take an operator as a character input and use it directly in calculations.

I realized that without using if or switch statements, there is no way to treat the character itself as an operator. I'm curious if anyone knows the reasons behind this limitation.

I wanted to use char ch = '+' and have the + character act as the addition operator

Comments
Post Details
Added on Jul 26 2024
1 comment
190 views