I have 3 double values x, y, z. I want to ask the user for an integer from 1 to 3.
If he types in a 1 i want to print the value x on the console. If he types 2 i want to pront the value y on the console and if he types in a 3 i want to print the value z to the console.
I know it is easy to do this with if else.
If(userinput ==1){
Print x
} else if (ussrinput ==2){
Print y
......}
Is there a way to do this without if else and switch case? I mean with a mathematical function or term.
Aucun commentaire:
Enregistrer un commentaire