String "Switch Case" simple code

string database
string c++
string example
string java
string python
string computer science
string minecraft
string javascript

I just started learning myself Java. Thought of writing a "Switch case" program like to get a input string from user and thought of displaying the day. Even though it did not show any errors in my Eclipse IDC but my below program is not running.

Could someone tell me what is the error in my below program?

package MyExercies;

import java.util.Scanner;

public class sampleSwitchCase 

{

    public static void main(String[] args) 
    {
        Scanner S = new Scanner(System.in);
        String Day = S.nextLine();
        int weekday = Integer.valueOf(Day);
        S.close();      
        switch(weekday)
        {
        case 1:     
            System.out.println ("The given day is Week begining day - Monday");
            break;

        case 2:
        case 3:
        case 4:
            System.out.println ("The given day is Mid of Weekday");
            break;

        case 5:
            System.out.println ("The given day is Weekend - Friday");
            break;

        case 6:
        case 7:
            System.out.println ("The given day is End of the Week");
            break;

        }

    }   

}

Everything is good and working with your Code!

Just add :

 default :
            System.out.println("Write something default  here");

String, Strings are objects that represent sequences of characters. The standard string class provides support for such objects with an interface similar to that of a  STRING is part of the ELIXIR infrastructure: it is one of ELIXIR's Core Data Resources. Learn more >

add default case in your code and try like this :

switch(weekday)
        {
        case 1:     
            System.out.println ("The given day is Week begining day - Monday");
            break;
        default:
            System.out.println("default case");

String, String Furniture - a Scandinavian design company offering storage solutions for every room. The flexible and iconic String® shelving system, the modern  A string is generally considered as a data type and is often implemented as an array data structure of bytes (or words) that stores a sequence of elements, typically characters, using some character encoding. String may also denote more general arrays or other sequence (or list) data types and structures.

Add a default case in your switch block. For example:

switch(exp) {
   case 1:
      break;
   default:
      break;
}

string - C++ Reference, JavaScript Strings. A JavaScript string stores a series of characters like "John Doe". A string can be any text inside double or single quotes: var carName1  Define string. string synonyms, string pronunciation, string translation, English dictionary definition of string. n. 1. a. Material made of drawn-out, twisted fiber, used for fastening, tying, or lacing. b. A strand or cord of such material. 2. Music a. A cord stretched

String (Java Platform SE 7 ), The string module contains a number of useful constants and classes, as well as some deprecated legacy functions that are also available as methods on strings  1000 Feet (c.333 Yards) 2mm 3 ply Colourful Natural Jute Twine String Roll Collection - 10 Assorted Coloured Variety Pack for Artworks and Crafts, Gift Wrapping

String Furniture, The String class represents character strings. All string literals in Java programs, such as "abc", are implemented as instances of this class. Strings are constant; their values cannot be changed after they are created. String buffers support mutable strings.

STRING, String Furniture - a Scandinavian design company offering storage solutions for every room. The flexible and iconic String® shelving system, the modern console shelf Museum™, sit-stand tables and more for the office from the Works™ assortment.

Comments
  • You should say more about what "not running" means.
  • Please stick to naming conventions. Package names and variable names (as well as method names) should start with a lower case character. Class names with upper case characters. So myExercise, SampleSwitchCase, s and day.
  • Posted code works here. Inefficient and non-standard variable names. But it works.
  • This code is working
  • Are you sure it doesn't run and not just wait for your input? Try printing something before your scanner so that you see if it ever starts.
  • Thanks for your prompt response. Added default section but still it is running without returning any result like showing red icon/button in my "Eclipse IDC".
  • Thanks for your prompt response. Added default section but still it is running without returning any result like showing red icon/button in my "Eclipse IDC".
  • default: is not a requirement but an option. How will this solve the OP's situation?
  • Thanks for your prompt response. Added default section but still it is running without returning any result like showing red icon/button in my "Eclipse IDC".