小编Ske*_*ner的帖子

可以在Java中的math.max中使用IF语句吗?

我想知道是否可以在math.max中使用if语句.例如,如果你有一个像这样的对象:

    public class Obj {
        private int i;
        private boolean b;
        public void setInt(int newInt) {
            this.i = newInt;
        }
        public void setBool(boolean newBool) {
            this.b = newBool;
        }
        public int getInt() {
            return this.i;
        }
        public boolean getIsTrue() {
            return this.b;
        }
    }
Run Code Online (Sandbox Code Playgroud)

初始化2个新对象并定义所有值后,是否可以执行以下操作:

    System.out.println(Math.max(if(obj1.getIsTrue()) {obj1.getInt()}, if (obj2.getIsTrue()) {obj2.getInt()}));
Run Code Online (Sandbox Code Playgroud)

我知道它可以通过数组和for循环来完成,所以我不会问它是否可能,只是可以以这种方式嵌套if语句.

java if-statement nested

-1
推荐指数
1
解决办法
213
查看次数

标签 统计

if-statement ×1

java ×1

nested ×1