Discuss / Java / 1

对酒当歌

#1 Created at ... [Delete] [Delete and Lock User]

public class 判断是否为小学生 {/// 三元运算符 b ? x : y,b为true则计算x,false则计算y,x和y的类型必须相同

    public static void main(String[] args) {// 小学生6-12

        int age = 7;

        boolean isPrimarystudent = age >= 6 && age <= 12;

        System.out.println(isPrimarystudent ? "yes" : "no");

    }

}


  • 1

Reply