本文整理 Java 入門核心語法要點,涵蓋 for/switch/while/do-while 流程控制細節、break/continue/return 跳轉差異、方法定義、三元運算符,適合初學者快速查閱鞏固。
for(init; condition; step) body 執行順序 1→2→4→3;單行可省略大括號case 穿透需 break;僅支持 byte/short/char/int/String/enum;多 case 共用代碼可堆疊public static void methodName(String param) {
// 方法體
}
int max = (a > b) ? a : b; // a>b 取 a,否則取 b