嗨,我碰巧遇到了我的朋友发给我的代码,并且我在编写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) 不是三元运算符假设像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)