2014-01-12 33 views
0

我有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]+")"); 
     } 
    }   
} 

回答

2

在這些行中,您正在重新設置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

1

在每次迭代中你說

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

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

相關問題