即时尝试测试二维数组的范围值,但它保持循环

即时尝试测试二维数组的范围值,但它保持循环

问题描述:

我有12个点的3个组我想测试,看看我的数组的12个点是否在395和405之间。然后,我想测试一个组中的所有3个点是否都在400以下。如果是,则输出消息,但是我的代码不断循环。有人可以为我检查吗?即时尝试测试二维数组的范围值,但它保持循环

tempi=i; 
tempx=x; 
for(i=0;i<3;i++) 
{ 
    for(x=0;x<4;x++) 
    { 
     if(rounded[i][x]<395 || rounded[i][x] >405) 
     { 
      System.out.println("there is an error with probes "+rounded[i][x]); 
     } 
     else if(values[i=0][x]< 400) 
     { 
      System.out.println("all points in element "+tempi+"as they are below 400 needs replaced("+"point "+tempx+" : "+values[i][x]+")");      
     } 
     else if(values[i=1][x]<400) 
     { 
      System.out.println("all points in element "+tempi+"as they are below 400 needs replaced("+"point "+tempx+" : "+values[i][x]+")"); 
     } 
     else if(values[i=2][x]<400) 
     { 
      System.out.println("all points in element "+tempi+"as they are below 400 needs replaced("+"point "+tempx+" : "+values[i][x]+")"); 
     } 
    }   
} 

在这些行中,您正在重新设置i的值。所以你永远不会退出循环是有道理的。

else if(values[i=0][x]< 400) 
.... 
else if(values[i=1][x]<400) 
.... 
else if(values[i=2][x]<400) 

我想你想要的是沿着线的东西:

else if(i == 0 && values[i][x]< 400) 
.... 
else if(i == 1 && values[i][x]<400) 
.... 
else if(i == 2 && values[i][x]<400) 
+0

作品谢谢但我真的需要嵌套for循环或将它运行没有 – user3188481

+0

对于二维数组,你通常需要嵌套循环。 – Zarathuztra

在每次迭代中你说

(values[i=0][x]< 400) 

等,你我值重置为0,1 ,和2。您可能想要使用i-0或i + 0。如果你正在检查的平等,使用==