lundi 10 février 2020

how can replace more then 16 if else-if statement Java

Im trying to make a program that allows the client to input a String. The string length should have 3 characters only and should contain the letters "A" "G" "C" "U".

My program have to pass through this table table and check what this string refers to..

Let's say the client passed this String "AUG", my program should show the name of this String which is "Met".

I made a code, and it worked but it has more then 15 if else-if condition.

My question is : Is there any other way to do it without using if else-if (or switch). And does polymorphism work in this case ?

Aucun commentaire:

Enregistrer un commentaire