【问题标题】:How would you go about scanning a file in java and counting the number of alphanumerical characters and vowels of that file?您将如何在 java 中扫描文件并计算该文件的字母数字字符和元音的数量?
【发布时间】:2013-02-11 23:01:56
【问题描述】:

我制作了一个可以读取文件的扫描仪,但是我对如何计算元音和字母/数字感到困惑。我想在 for 循环中使用 .chartAt(i) 但你不能在 Scanner 类中使用 .charAt() 。很想知道如何解决这个问题

【问题讨论】:

  • 我会阅读文件并计数。为什么你觉得你需要使用 Scanner?

标签: java readfile


【解决方案1】:

这将计算字母数字:

int alphaNumericCount = input.split("(?<=[A-Za-z0-9])").length - 1;

这将计算元音:

int vowelCount = input.split("(?<=[AEIOUaeiou])").length - 1;

您在文件中的读取方式取决于您。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-06-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多