user2012751
user2012751

Reputation: 153

How would you go about scanning a file in java and counting the number of alphanumerical characters and vowels of that file?

I've made a scanner which reads the file but then I'm confused on how to count the vowels and letters/numbers. I want to use .chartAt(i) in a for loop but you can't use .charAt() in the Scanner class. Curious to see how to go about this problem

Upvotes: 0

Views: 79

Answers (1)

Bohemian
Bohemian

Reputation: 425198

This will count alpha numerical:

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

This will count vowels:

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

How your read in the file is up to you.

Upvotes: 1

Related Questions