0

我创建了一种在导入的文本文件中搜索浮点数数量的方法。该文件本身有超过 20 个浮点数,但我一直得到 0 作为文本中浮点数的数量。该方法是布尔值,并逐个字符地搜索文本文件。然后 main 方法使用布尔值来计算浮点数

public static boolean isFloat(String token) {
    if(!(token).contains(".")) return false;
    if (token.startsWith("+") || token.startsWith("-")) {  
    for (int i = 0; i < token.length(); i++) {
            if (! Character.isDigit((token).charAt(i))) {
                if (!token.contains("."))
                    return false;
            }
        }   
    }

    return true;
}

Loop within main: 
while (checkFile.hasNext()) {
    words = checkFile.next();
    if (!notWord == isWord(words)) {
        word++;

    } else if (! notDigit == isInteger(digits)) {
        number++;
    } else if (!notFloat == isFloat(floatNum)) {
        decimalNum++;
    }
}
4

0 回答 0