?
Solved

Can you use strings in Switch/Case statements?

Posted on 2003-03-24
3
Medium Priority
?
220 Views
Last Modified: 2010-03-31
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
Comment
Question by:thunderflash
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 

Author Comment

by:thunderflash
ID: 8199735
also "codon" would be a string
0
 
LVL 3

Expert Comment

by:allahabad
ID: 8199757
No, it has to be int or char type:

0
 
LVL 92

Accepted Solution

by:
objects earned 225 total points
ID: 8199786
you need to use:

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


0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month11 days, 18 hours left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question