赞
踩
if (条件){执行语句}
class FirstTest{
static void main(String[] args) {
def a = 1
if (a==1){
println "单分支语句"
}
}
}
if (条件) {执行语句} else {执行语句}
class FirstTest{
static void main(String[] args) {
def a = 1
if (a==0){
println "a的值为0"
} else {
println "a的值不为0"
}
}
}
if (条件1) {执行语句1} else if (条件2) {执行语句2} else {执行语句3}
class FirstTest{
static void main(String[] args) {
def a = 1
if (a == 0){
println "a的值为0"
} else if (a == 1){
println "a的值为1"
} else {
println "a的值不是0也不是1"
}
}
}
switch(n){case n=a -> 执行语句a case n=b -> 执行语句b default -> 默认执行语句}
class FirstTest{
static void main(String[] args) {
def num = 3
switch (num){
case 1 ->
println "num的值为1"
case 2 ->
println "null的值为2"
default -> println "不知道num的值"
}
}
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。