Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Switch help?

 
xiao sean
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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..
thanks
----------------
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
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"sayno,"

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.
 
xiao sean
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi , thanks for yr info.

but i have a doubt. what is a single quote?
 
xiao sean
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ohh i get what you meant.. thanks for the help..
really appricated..
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15214
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic