Learning Switch Statements: Add/Subtract/Multiply/Divide Equations

  • Thread starter Thread starter Peach
  • Start date Start date
  • Tags Tags
    Switch
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
1 reply · 3K views
Peach
Messages
80
Reaction score
0
I'm new to programming and learning the switch statements right now. I'm wondering if you can add/subtract/multiply/divide equations in the switch statements.

Example: y = x^6/6

And if I want that in case 1, how do I calculate y assuming I already have x input beforehand?
 
Physics news on Phys.org
In Java cases in a switch statement need to be constant primitive types or enumerated types. C# relaxes this a little adding support for strings. But you can't have the following:
Code:
switch(y){
   case Math.Pow(x, 6)/6:
          //do something
   case Math.PI*Math.Pow(x, 2):
          //do something else
}