小编Leo*_*nne的帖子

为什么这个数组到2d数组布尔值为true?

嗨,我碰巧遇到了我的朋友发给我的代码,并且我在编写print语句的第二部分时遇到了麻烦.. a[3]是4,这是在第0行第2列(b[0][2]),但为什么a[2]是53,证明真的b[2][1] == 43??? (代码打印'真实'顺便说一下.)

class Ex1{
     public static void main(String[] args) {

         int a[] = { 1,2,053,4};
         int b[][] = { {1,2,4} , {2,2,1},{0,43,2}};

         System.out.print(a[3]==b[0][2] );
         System.out.print(" " + (a[2]==b[2][1]));
  }
}
Run Code Online (Sandbox Code Playgroud)

java arrays syntax boolean

3
推荐指数
1
解决办法
394
查看次数

为什么我的三元布尔运算符显示相反的结果

不是三元运算符假设像arg一样工作?真假 ???所以如果持续时间和石油超过规定的数量而不是字段变量,它应该返回true ..但是这会返回false

public class test12 {
    int duration = 260;
    int petroleum = 300;
    boolean result;

    public void checktrain(){
        boolean result = duration>=250 && petroleum>=235? true : false;
        this.result = result;
    }

    public void run(){
        System.out.print(result);
    }

    public static void main(String args[]){
        test12 tr = new test12();
        tr.run();
    }
}
Run Code Online (Sandbox Code Playgroud)

java boolean return ternary operator-keyword

0
推荐指数
1
解决办法
120
查看次数

标签 统计

boolean ×2

java ×2

arrays ×1

operator-keyword ×1

return ×1

syntax ×1

ternary ×1