Read from a text file and find the word with the most consecutive vowels. Help me
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class ConsecutiveVowels {
public static void main(String[] args) {
Scanner fileIn = null;
try
{
// Attempt to open the file
fileIn = new Scanner (new FileInputStream("words.txt"));
}
catch (FileNotFoundException e)
{
//This block is executed if the file is not found
//and then the program exits
System.out.println("File not found");
System.exit(0);
}
String theWord;
int vowelCount = 0;
fileIn.hasNextLine();
theWord = fileIn.next();
System.out.println("The word that has the most consecutive vowels is: ");
for (int i = 0; i < theWord.length(); i ++ )
{
char c = theWord.charAt(i);
if ( (c == 'A') || (c == 'a')
|| (c == 'E') || (c == 'e')
|| (c == 'I') || (c == 'i')
|| (c == 'O') || (c == 'o')
|| (c == 'U') || (c == 'u'))
{
vowelCount = vowelCount + 1;
}
}
}
}
Re: Read from a text file and find the word with the most consecutive vowels. Help me
I don't see a question in your post...I recommend asking one if you wish to receive help. If there are errors, post them in their entirety, and wrap all code in the code tags