下面这段代码的结果为什么不是 See no evil. 而是 See no evil. Speak no evil. Hear no evil. public class Advice { public final static int LITTLE_ADVICE = 0; public final static int MORE_ADVICE = 1; public final static int LOTS_OF_ADVICE = 2; public static void main(String[] args) { dispenseAdvice(LOTS_OF_ADVICE); } public static void dispenseAdvice(int howMuchAdvice) { switch(howMuchAdvice) { // (1) case 2: System.ou
c*p
3 楼
对预防霉菌很管用,喜欢
g*g
4 楼
If you don't break in each case, it will follow through.
【在 d********o 的大作中提到】 : 下面这段代码的结果为什么不是 : See no evil. : 而是 : See no evil. : Speak no evil. : Hear no evil. : public class Advice { : public final static int LITTLE_ADVICE = 0; : public final static int MORE_ADVICE = 1; : public final static int LOTS_OF_ADVICE = 2;
Z*X
5 楼
谢谢,我的桔子树生病了,叶子背面先有一层白色的膜,然后卷起来,心痛ing, 不知 Neem oil 能否治我的桔子树。
【在 c***p 的大作中提到】 : 对预防霉菌很管用,喜欢
a*e
6 楼
在这方面C#和Perl设计得更合理。
【在 g*****g 的大作中提到】 : If you don't break in each case, it will follow through.
【在 Z**X 的大作中提到】 : 谢谢,我的桔子树生病了,叶子背面先有一层白色的膜,然后卷起来,心痛ing, 不知 : Neem oil 能否治我的桔子树。
d*o
8 楼
有点不明白,LOTS_OF_ADVICE的值自始至终是2, 为什么语句(3)和语句(4)也执行 了。什么是fallow through?follow through 是不是将所有的Case语句执行一遍! case 1: System.out.println("Speak no evil.");也执行了, 难道说LOTS_OF_ADVICE 变量值会自动递减!
【在 g*****g 的大作中提到】 : If you don't break in each case, it will follow through.
If you ever learn assembly, you'll understand why this is natural. "case blahblah" is a just a label. You can have as many labels as you like but the flow won't change until you do jump ("break"). C used this design and C++, Java followed.
ADVICE
【在 d********o 的大作中提到】 : 有点不明白,LOTS_OF_ADVICE的值自始至终是2, 为什么语句(3)和语句(4)也执行 : 了。什么是fallow through?follow through 是不是将所有的Case语句执行一遍! : case 1: System.out.println("Speak no evil.");也执行了, 难道说LOTS_OF_ADVICE : 变量值会自动递减!
【在 g*****g 的大作中提到】 : If you ever learn assembly, you'll understand why this is natural. : "case blahblah" is a just a label. You can have as many labels as : you like but the flow won't change until you do jump ("break"). : C used this design and C++, Java followed. : : ADVICE
l*G
14 楼
matlab does not need breaks, yet many need, so it is language-dependent, you should be very carefull