java中的什么意思

java中的什么意思,java,Java,我试图用java理解这个程序,但我对这种语言不熟悉 你能告诉我什么吗 <=0?0:1; 意味着什么 下面的代码减少了矩阵禁忌的元素 public void decrementTabu(){ for(int i = 0; i<tabuList.length; i++){ for(int j = 0; j<tabuList.length; j++){ tabuList[i][j]-=tabuList[i][j]<

我试图用java理解这个程序,但我对这种语言不熟悉

你能告诉我什么吗

<=0?0:1;
意味着什么

下面的代码减少了矩阵禁忌的元素

 public void decrementTabu(){
        for(int i = 0; i<tabuList.length; i++){
           for(int j = 0; j<tabuList.length; j++){
            tabuList[i][j]-=tabuList[i][j]<=0?0:1;
         } 
        }
    }

您没有正确地查看操作员

这是,它是JavaScript或Java以及其他语言(如C)中唯一的三元运算符。三元表示它有三个参数

本质上,这就是它的含义:

(condition)?(true branch):(false branch)
  param1        param2        param3
在代码示例中,条件param1为:

tabuList[i][j]<=0
可以写为:

if (tabuList[i][j] > 0)
   tabuList[i][j]--;
int tabuListEntry = tabuList[i][j];
tabuListEntry -=tabuListEntry <=0?0:1;
int tabuListEntry = tabuList[i][j];
tabuListEntry = tabuListEntry - (tabuListEntry <=0?0:1);
int tabuListEntry = tabuList[i][j];
int decrementAmount = tabuListEntry <=0?0:1;
tabuListEntry = tabuListEntry - decrementAmount ;
int tabuListEntry = tabuList[i][j];
int decrementAmount = 0; 
if(tabuListEntry  <= 0) {
    decrementAmount = 0;
} else {
    decrementAmount = 1;
}
tabuListEntry = tabuListEntry - decrementAmount ;
int tabuListEntry = tabuList[i][j];
int decrementAmount = 0; 
if(tabuListEntry  > 0) {
    decrementAmount = 1;
}
tabuListEntry = tabuListEntry - decrementAmount ;
int tabuListEntry = tabuList[i][j];
if(tabuListEntry  > 0) {
    tabuListEntry = tabuListEntry - 1;
}
可以写为:

if (tabuList[i][j] > 0)
   tabuList[i][j]--;
int tabuListEntry = tabuList[i][j];
tabuListEntry -=tabuListEntry <=0?0:1;
int tabuListEntry = tabuList[i][j];
tabuListEntry = tabuListEntry - (tabuListEntry <=0?0:1);
int tabuListEntry = tabuList[i][j];
int decrementAmount = tabuListEntry <=0?0:1;
tabuListEntry = tabuListEntry - decrementAmount ;
int tabuListEntry = tabuList[i][j];
int decrementAmount = 0; 
if(tabuListEntry  <= 0) {
    decrementAmount = 0;
} else {
    decrementAmount = 1;
}
tabuListEntry = tabuListEntry - decrementAmount ;
int tabuListEntry = tabuList[i][j];
int decrementAmount = 0; 
if(tabuListEntry  > 0) {
    decrementAmount = 1;
}
tabuListEntry = tabuListEntry - decrementAmount ;
int tabuListEntry = tabuList[i][j];
if(tabuListEntry  > 0) {
    tabuListEntry = tabuListEntry - 1;
}

这是一个假设条件,将采用cIt的if/then查询的简短形式:tabuList[i][j]基本上要求家庭作业帮助,快速浏览任何教程或语言书籍都会显示出来。这是一个古老的条件,但这只适用于方形数组。第二个for循环应该是forint j=0;j在大多数示例中,您都错过了tabuList[i][j]的作业。@Oded是的,谢谢您指出。将修改后的值重新分配回数组将留给用户作为练习-每个高中数学书都会这样写