File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Switch help? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Switch help?" Watch "Switch help?" New topic

Switch help?

xiao sean
Ranch Hand

Joined: Aug 20, 2007
Posts: 44
hi guys.
i need some help here as i'm unable to debug this program. i just pick up basic java programming.

my output always will become default, which i have no idea where went wrong, appricated help from you guys..
class Displayday
public static void main (String[]args)

int day = Integer.parseInt (args[0]);

switch ( day )
case '1': System.out.println("today is monday"); break;
case '2': System.out.println("today is tuesday"); break;
case '3': System.out.println("today is wednesday"); break;
case '4': System.out.println("today is thursday"); break;
case '5': System.out.println("today is friday"); break;
case '6': System.out.println("today is saturday"); break;
case '7': System.out.println("today is sunday"); break;
default : System.out.println(" Sorry, Wrong i/p. Try again");

marc weber

Joined: Aug 31, 2004
Posts: 11343


Welcome to JavaRanch! Please check your private messages by clicking on the "My Profile" link near the top of the page.

Your cases have the ints in single quotes, which make them chars. Remove the single quotes, and it should work.

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
xiao sean
Ranch Hand

Joined: Aug 20, 2007
Posts: 44
hi , thanks for yr info.

but i have a doubt. what is a single quote?
xiao sean
Ranch Hand

Joined: Aug 20, 2007
Posts: 44
ohh i get what you meant.. thanks for the help..
really appricated..
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15101

"sean", your name is still not according to the JavaRanch policy. Please take a moment to read the policy carefully. Your name must consist of a first name, space, and a second name. Not just a first name.

Please change your display name again so that it conforms to the policy. You can change your name by editing your profile.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
I agree. Here's the link:
subject: Switch help?
It's not a secret anymore!