Java 如何打印连续元音最多的单词?

Java 如何打印连续元音最多的单词?,java,Java,我不知道我的编程哪里出错了。目标是加载一个文件并查找具有最多连续元音的单词。这个代码没有给我正确的单词。它给了我“aalii”,当它应该给我“cooeeing”的时候,有人能帮我吗 import java.io.FileInputStream; import java.io.FileNotFoundException; import java.util.Scanner; public class manyVowels { public static void main(String[

我不知道我的编程哪里出错了。目标是加载一个文件并查找具有最多连续元音的单词。这个代码没有给我正确的单词。它给了我“aalii”,当它应该给我“cooeeing”的时候,有人能帮我吗

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class manyVowels {

    public static void main(String[] args) {

        Scanner fileIn = null;
        try {
            //locate and open file
            fileIn = new Scanner(new FileInputStream("words.txt"));
        } catch (FileNotFoundException e) {
            //if the file cannot be found, the program prints the message and quits
            System.out.println("File not found. ");
            System.exit(0);
        }
        String word;
        if (fileIn.hasNext()) //if there is another word do as shown below
        {
        //seek consecutive vowels
        word = fileIn.next();
            for(int i=0;i <word.length();i++){
                if((word.charAt(i) == 'A') || 
                    (word.charAt(i) == 'E') ||
                    (word.charAt(i) == 'I') || 
                    (word.charAt(i) == 'O') ||
                    (word.charAt(i) == 'U') ||
                (word.charAt(i) == 'a') || 
                    (word.charAt(i) == 'e') ||
                    (word.charAt(i) == 'i') || 
                    (word.charAt(i) == 'o') ||
                    (word.charAt(i) == 'u')) {
            //prints the final word with the most consecutive vowels
            System.out.println("The word with the most consecutive vowels is: " + word);
            System.exit(0);
        }

        fileIn.close();
    }
}}}
import java.io.FileInputStream;
导入java.io.FileNotFoundException;
导入java.util.Scanner;
公共级多电源{
公共静态void main(字符串[]args){
Scanner fileIn=null;
试一试{
//找到并打开文件
fileIn=newscanner(newfileinputstream(“words.txt”);
}catch(filenotfounde异常){
//如果找不到文件,程序将打印消息并退出
System.out.println(“未找到文件”);
系统出口(0);
}
字符串字;
if(fileIn.hasNext())//如果有其他单词,请按如下所示执行
{
//寻找连续元音
word=fileIn.next();
for(int i=0;i最大元音){
最大元音=元音;
finalWord=单词;
}
元音=0;
}
}
//比较元音和最大元音
如果(元音>最大元音){
最大元音=元音;
finalWord=单词;
}
}
//寻找元音
word=fileIn.next();
for(int i=0;i
而不是

if(fileIn.hasNext()) 使用
虽然(fileIn.hasNext())

尝试用普通语言编写程序,但实际上并不是在检查有多少个连续元音

Open file
If the file contains a word, continue
For each letter in the first word do:
    if the letter is a vowel,
        print "The word with the most consecutive vowels is: " + word
        exit the program
所以你实际上不是在检查有多少个连续的元音,而是在检查第一个单词中是否有元音


试着写一些你想做的伪代码,就像我在你写程序之前所做的那样,你没有排序,只是打印单词…
它应该给我“咕咕”
为什么它应该给你这个?哦@Sebas。我应该会很高兴因为文件上的字(这是一个很长的单词列表,其中有一个元音最多的单词。@stephaniegross2您的文件内容是什么?编写的代码将读取文件中的第一个单词。如果该单词有元音,它将打印消息。然后程序退出,不再读取任何单词。一次读取一行文件的程序必须包含某种循环。你的程序不包含循环。如果你不明白这一点,是时候去和你的教授或助教谈谈了。如果我们只是帮你做作业,你什么都学不到。op想要的是最连续的元音,不仅仅是找到一个Yea,我可能有点不清楚,但我想他最清楚wh关键是他真正检查的是第一个单词是否包含元音