Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Switch strings

Posted on 2004-10-08
6
Medium Priority
?
166 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

610 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