2.switch(a++%4)这个过程a是先与4进行求余,然后a会递增一次,也就是+1
3.switch(++a%4)这个过程a是先递增+1,然后再与4进行求余
4.case 如果没有break会发生case穿透,不会跳出,会进行下一个case执行要求!
5.给你截图了,能不能看懂全靠造化了,尽力了,不可能全部都列出步骤,列出打印4的原因:
import java.io.Fileimport java.util.Scanner
public class Test {
public static void main(String[] args) {
System.out.println("行数: " + getLineCountOfFile("c:\\1.txt"))
}
public static int getLineCountOfFile(String filePath) {
int lineCount = 0
Scanner scanner = null
try {
scanner = new Scanner(new File(filePath))
while (scanner.hasNextLine()) {
System.out.println("文件内容: " + scanner.nextLine())
++lineCount
}
} catch (Exception e) {
} finally {
if (scanner != null) {
scanner.close()
}
}
return lineCount
}
}
int x = 9, yif (x >= 0) {
if (x > 0) {
y = 1
} else {
y = 0
}
} else {
y = -1
}
System.out.println(y)
知识点:if else 后面的括号可以省略,条件成立执行下面一句代码。
建议:这种省略的做法非常不可取,可读性差,只适合给喜欢骚操作的人使用。