0

インポートしたテキスト ファイル内の浮動小数点数の量を検索するメソッドを作成しました。ファイル自体には 20 を超える浮動小数点数がありますが、テキスト内の浮動小数点数として 0 を取得し続けます。このメソッドはブール値で、テキスト ファイルを 1 文字ずつ検索します。メイン メソッドは、ブール値を使用して float の数をカウントします。

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