学习型 ASP/PHP/ASP.NET 主机 30元/年全能 ASP/PHP/ASP.NET 主机,支持月付专业 MSSQL 数据库空间,支持月付专业 MySQL 数据库空间,支持月付
发新话题
打印

[求助]help help assignment

[求助]help help assignment

In one of the steps of the assignment, in says this: Write a method in the Board Class which is given a character c. The method should determine if any of the rows in the board contain a sequence of 4 or more of the given characters (e.g. if we have "connected four"). The method should return true if such a sequence exists in the board and false otherwise.

NOTE: The whole assignment is about creating a board , the getRow(int i) will return the index of i row as a String, and getSequence(char c,int i) is just return a String that contains i number of char c.

what I wrote didnt work, can any one tell me why???

public boolean isConnectedFour(char c){ boolean notStop = true; if(getRow(0).length()>=FOUR){ for(int i = 0; i<size && notStop; i++){ int index =getRow(i).indexOf(c); if(getRow(i).substring(index,index+4).equals(getSequence(c,FOUR))){ notStop = false; return true; } else return false;

}

} else return false;

}

TOP

Oh, I just forgot, FOUR is a static final variable. as public static final int FOUR = 4;
Anstey. Cheers. I love CAPPUCCINO~~

TOP

Can you describe it more clearly?Do you mean if a String contain FOUR then return true?And some ESC char in you code like &gt;  dose it inputed by mistake?
相信勤能补拙! 喜欢用好用的就永远学不到有用的。

TOP

this is just getting strange, i dont know why that happens to my code when i put them in fourm, but anyway, i sovled that problem already

cheers.

Anstey. Cheers. I love CAPPUCCINO~~

TOP

发新话题