zoukankan      html  css  js  c++  java
  • Switch

     1 /**
     2  * JDK7.0新特性  7.0以前 表达式的结果只能是int(或者可以自动转成int的 byte short char)枚举类型
     3  *   7.0之后 表达式可以是 字符串!
     4  *   如果想看效果 就装上7以上的版本
     5  */
     6 public class TestSwitch {
     7     public static void main(String[]args){
     8         double d =Math.random();
     9         int e= 1+(int)(d*6);
    10 
    11         System.out.println("您的点数是:"+e);
    12         
    13         switch(e){
    14             //JDK7中可以放字符串
    15         case 6:
    16             System.out.println("走大运了!");
    17             break;
    18         case 5:
    19             System.out.println("运气不错哦,继续加油");
    20             break;
    21         case 4:
    22             System.out.println("加油啊");
    23             break;
    24         case 3:
    25             System.out.println("运气一般");
    26             break;
    27         case 2:
    28             System.out.println("运气不行啊");
    29             break;
    30         default:
    31             System.out.println("倒霉");
    32             break;
    33 
    34         }
    35 
    36         System.out.println("欢迎下次光临");
    37         
    38         System.out.println("26的字母随机一次,判断那些是元音,半元音,辅音?");
    39         char a='a';
    40         int b= (int)(1+26*Math.random());
    41         char c= (char)(a+b);
    42         System.out.println("您随机的字母是:"+c);
    43         switch(c){
    44         case 'a':
    45         case 'e':
    46         case 'i':
    47         case 'o':
    48         case 'u':
    49             System.out.println("元音");
    50         break;
    51         case 'y':
    52         case 'w':
    53             System.out.println("半元音");
    54         default:
    55             System.out.println("辅音");
    56         }
    57 
    58     }
    59 }
  • 相关阅读:
    查询语句
    索引的增删改成查
    pymysql模块
    mysql备份
    单表查询语法
    单表查询
    mysql增删改差
    Leetcode--1. Two Sum(easy)
    Leetcod--20. Valid Parentheses(极简洁的括号匹配)
    Leetcode-448. Find All Numbers Disappeared in an Array(solve without extra space easy)
  • 原文地址:https://www.cnblogs.com/PoeticalJustice/p/7608780.html
Copyright © 2011-2022 走看看