Solved

Switch strings

Posted on 2004-10-08
6
160 Views
Last Modified: 2012-05-05
Hi there

I'm trying to write a program where I can enter a day of the week, and feedback whether its falls during the week or weekend. I want to use a switch statement. Can you tell me how I convert the string so that I can use it in the switch?
0
Comment
Question by:moggiek
6 Comments
 
LVL 14

Accepted Solution

by:
Tommy Braas earned 25 total points
ID: 12263341
You can convert the day of the week to an integer and the use a switch statement. If you add all the names of the days of a week into a HashMap as keys and the corresponding day number as the value. You would however have to set that HashMap up in the first place.
0
 
LVL 9

Expert Comment

by:DrWarezz
ID: 12263378
Might I ask, why must it use a "switch" statement?
 -I hate to be nosy, but, it sounds like POSSIBLE homework. Which we're not alowed to help you with.

;) Just so you know
[r.D]
0
 
LVL 3

Expert Comment

by:CI-Ia0s
ID: 12263603
Hrmm... I thought the rule was no code-blocks (i.e. doing the program for them), but we can give general advice/code snippets? (http://www.experts-exchange.com/Programming/Programming_Languages/Java/help.jsp#hi130)

Meh, my only comment would be that you could also use if-statements:
if (dayInput.equals("Sunday")){dayInt = 1;}
else if (dayInput.equals("Monday")){dayInt = 2;}

etc.
0
 
LVL 92

Assisted Solution

by:objects
objects earned 25 total points
ID: 12273074
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Java JRE greater than 1.6 5 63
hibernate example issues from command prompt 10 42
iterator/ListIterator approach 17 29
Java Restore security prompts not working 10 17
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…

825 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