Advertisement
mllm

switch and case

Mar 8th, 2017
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.23 KB | None | 0 0
  1. /** A simple script inspired from this C++ example : https://www.macs.hw.ac.uk/~pjbk/pathways/cpp1/node105.html
  2. *
  3. * INPUT: Integer (1 to 7), with 1 being "Sunday".
  4. * OUTPUT: Day of the week, if successful, "Not an allowable day number" if not.
  5. **/
  6. import java.util.*;
  7.  
  8. public class Day {
  9.     public static void main(String[] args) {
  10.         System.out.println("Input a number from 1-7 of the day of the week.");        
  11.         Scanner scan = new Scanner(System.in);
  12.         int day = scan.nextInt();
  13.                
  14.         switch (day)
  15.         {
  16.            case 1 : System.out.println("Sunday");
  17.                     break;
  18.            case 2 : System.out.println("Monday");
  19.                     break;
  20.            case 3 : System.out.println("Tuesday");
  21.                     break;
  22.            case 4 : System.out.println("Wednesday");
  23.                     break;
  24.            case 5 : System.out.println("Thursday");
  25.                     break;
  26.            case 6 : System.out.println("Friday");
  27.                     break;
  28.            case 7 : System.out.println("Saturday");
  29.                     break;
  30.            default : System.out.println("Not an allowable day number");
  31.                     break;
  32.         }                
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement