在下面的代碼,我算字符串的編號,然後嘗試檢查數量匹配值 的代碼是正確的,但我不知道如何將一個矩陣比較計數值:如何比較表?
例如:計數器1給出:
10
150
10
0
200
我需要檢查它是否匹配值?
int[][] values = { { 10, 150, 10, 0, 10, 200 }, { 20, 5, 18, 60, 14, 0 }, { 16, 5, 18, 20, 25, 30 } };
for (int i = 1; i < 4;i++)
{
//do action here
int counter1 = 0;
int counter2 = 0;
int counter3=0;
int counter4=0;
int counter5=0;
int counter6=0;
for (int j = 0; j < myTableNbRows; i++)
{
if (myTable.getValue(j, 0).matches("hello"))
{
if (myTable.getValue(j, 1).contains("tions."))
{
counter1++;
}
if (myTable.getValue(j, 1).contains("ons."))
{
counter2++;
}
if (myTable.getValue(j, 1).contains("an."))
{
counter3++;
}
if (myTable.getValue(j, 1).contains("auns."))
{
counter4++;
}
if (myTable.getValue(j, 1).contains("896."))
{
counter5++;
}
if (myTable.getValue(j, 1).contains("1222."))
{
counter6++;
}
}
}
//here I nedd to compare values with counter
assertEquals(values,counter1);
assertEquals(values,counter2);
....
你能舉一個例子,你的意思是「比較值與計數器」?我假設例如counter1的值是否在數組「values」中的某處! – nyxz
我需要使用assertEquals來驗證值==計數器 – lola
提示:修復縮進以使代碼結構易於閱讀。 – Kelvin