public class Main { public static void main(String[] args) { String fruit = "orange"; int opt = switch (fruit) { case "apple" : yield 1; case "pear", "mango" : yield 2; default : int code = fruit.hashCode(); yield code; // switch语句返回值 }; System.out.println("opt = " + opt); } }
Sign in to make a reply
Zlstg