【发布时间】:2017-12-09 20:46:55
【问题描述】:
我需要一些关于我正在使用的方法的帮助。 我的第一个方法查看字符串 s 中第一个(第 0 个)之后的每个字符,并检查它们是否是数字,但我无法让它完全工作。
/**
* Forms the latter 5 characters of the accountNum String into a substring
which is checked to
* see if all characters are positive integers
*/
public Boolean hasValidDigits(String s)
{
for(int i=1; i<s.length(); i++)
if (Character.isDigit(s.charAt(i))) {
return true;
}
}
该方法的问题是它要求为“for”提供返回语句,我不知道为什么。
我的第二个方法调用类其他部分的方法来检查字符串 s。
/**
* Checks the following three criteria:
* - Is a string of length 6
* - Starts with a capital Letter
* - Subsequent characters are positive integers
*/
public Boolean isValidAccountNum(String s)
{
if (s.isValidLength() s.isValidStart() s.hasValidDigits()) {
return true;
} else {
return false;
}
}
这个方法的问题是它说“找不到符号 - 方法 isValidLength()
我猜它会与其他方法有相同的错误。
我想调用的方法都是公开的。我将在下面包含 isValidLength()。
/**
* Checks if the variable accountNum has a length of 6 characters
*/
public Boolean isValidLength(String s)
{
if (s.length()==6) {
return true;
} else {
return false;
}
}
【问题讨论】: