fork download
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4. // SwitchExercises
  5.  
  6. public static void main (String[] args) {
  7. System.out.println("Enter week's day using a number");
  8. Scanner scanner = new Scanner(System.in);
  9. int dayOfWeek = scanner.nextInt();
  10. String weekTitle;
  11.  
  12. switch (dayOfWeek) {
  13. case 1:
  14. weekTitle = "Monday";
  15. break;
  16. case 2:
  17. weekTitle = "Tuesday";
  18. break;
  19. case 3:
  20. weekTitle = "Wednesday";
  21. break;
  22. case 4:
  23. weekTitle = "Thursday";
  24. break;
  25. case 5:
  26. weekTitle = "Friday";
  27. break;
  28. case 6:
  29. weekTitle = "Saturday";
  30. break;
  31. case 7:
  32. weekTitle = "Sunday";
  33. break;
  34. default:
  35. weekTitle = "Entered unknown item";
  36. }
  37.  
  38. System.out.println(weekTitle);
  39. scanner.close();
  40. }
  41. }
  42.  
  43.  
  44.  
  45. // if (dayOfWeek == 1) {
  46. // weekTitle = "Monday";
  47. // } else if (dayOfWeek ==2) {
  48. // weekTitle = "Tuesday";
  49. // } else if (dayOfWeek ==3) {
  50. // weekTitle = "Wednesday";
  51. // } else if (dayOfWeek ==4) {
  52. // weekTitle = "Thursday";
  53. // } else if (dayOfWeek ==5) {
  54. // weekTitle = "Friday";
  55. // } else if (dayOfWeek ==6) {
  56. // weekTitle = "Saturday";
  57. // } else if (dayOfWeek ==7) {
  58. // weekTitle = "Sunday";
  59. // } else {
  60.  
Success #stdin #stdout 0.11s 56640KB
stdin
4
stdout
Enter week's day using a number
Thursday