Demo09.java 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package com.lovecoding.J20250518;
  2. /**
  3. * @author WanJl
  4. * @version 1.0
  5. * @title Demo09
  6. * @description switch语句
  7. * @create 2025/5/18
  8. */
  9. public class Demo09 {
  10. public static void main(String[] args) {
  11. /*
  12. switch(变量){
  13. case 常量1:
  14. 语句1;
  15. break;
  16. case 常量2:
  17. 语句2;
  18. break;
  19. case 常量3:
  20. 语句3;
  21. break;
  22. .....
  23. default:
  24. 语句n;
  25. }
  26. switch使用的类型可以是byte、short、int、char、String
  27. */
  28. String a="星期一111";
  29. switch (a){
  30. case "星期一":
  31. System.out.println("今天星期一");
  32. break;
  33. case "星期二":
  34. System.out.println("今天星期二");
  35. break;
  36. case "星期三":
  37. System.out.println("今天星期三");
  38. break;
  39. case "星期四":
  40. System.out.println("今天星期四");
  41. break;
  42. case "星期五":
  43. System.out.println("今天星期五");
  44. break;
  45. case "星期六":
  46. System.out.println("今天星期六");
  47. break;
  48. case "星期日":
  49. System.out.println("今天星期日");
  50. break;
  51. default:
  52. System.out.println("不知道...");
  53. }
  54. }
  55. }