?
Solved

Switch strings

Posted on 2004-10-08
6
Medium Priority
?
163 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
[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
6 Comments
 
LVL 14

Accepted Solution

by:
Tommy Braas earned 100 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 100 total points
ID: 12273074
0

Featured Post

Introducing Priority Question

Increase expert visibility of your issues by participating in Priority Question, our latest feature for Premium and Team Account holders. Adjust the priority of your question to get emergent issues in front of subject-matter experts for help when you need it most.

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses
Course of the Month15 days, 8 hours left to enroll

743 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