• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 226
  • Last Modified:

Can you use strings in Switch/Case statements?

I am a novice programmer and i was wondering if i can use strings in the switch statement.
i was wondering if this type of code would work:

switch (codon){
    case "GGG": return "Phe ";
    case "GGU": return "Met ";
    etc...

(im writing a program that translates RNA code into its corrisponding chain of amino acids, aka a polypeptide)
0
thunderflash
Asked:
thunderflash
1 Solution
 
thunderflashAuthor Commented:
also "codon" would be a string
0
 
allahabadCommented:
No, it has to be int or char type:

0
 
objectsCommented:
you need to use:

if ("GGG".equals(codon))
{
  return "Phe ";
}
else if ("GGU".equals(codon))
{
  return "Met ";
}
etc.


0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now