• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Switch help?

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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");
}
}
}

------------
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ohh i get what you meant.. thanks for the help..
really appricated..
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic