学习日记五

初识Java(三)

  1. switch语句中的变量类型可以是:
    • byte、short、int或者char.
    • 从Java SE7开始支持字符串类型
    • case标签必须为字符串常量或字面量
//switch判断字符串是将字符串转为哈希值再判断
String name = "孤星";
switch (name){
   case "孤星":
   	System.out.println("孤星");
    	break;
    case "零一":
        System.out.println("零一");
        break;
    default:
        System.out.println("瞎几把输");
        break;
}
//编译过后再反编译代码
String name = "孤星";
byte var3 = -1;
switch(name.hashCode()) {
    case 751419:
       if (name.equals("孤星")) {
           var3 = 0;
       }
       break;
    case 1217994:
       if (name.equals("零一")) {
	   var3 = 1;
       }
}
switch(var3) {
    case 0:
        System.out.println("孤星");
        break;
    case 1:
        System.out.println("零一");
        break;
    default:
        System.out.println("瞎几把输");
}
  1. IDEA编辑器可以使用 100.for+tab快捷打出for循环
100.for =>for(int i = 0; i < 100; i++){}
int[] a = {10,20,30,40,50};
a.for => for (int i : a) {}
  1. java文件一定要在它的包路径下才能执行
package com.gxh;//包路径
Java com.gxh.Hello //命令行执行要有包路径
  1. 递归一般是不被推荐的,非常容易造成内存溢出的。当然,适当的利用递归的确可以简化代码
posted @ 2021-02-25 09:35  孤星寒  阅读(55)  评论(0)    收藏  举报