小编Tim*_*mmy的帖子

元音按字母顺序排列的单词

该程序的目标是从单词列表中返回包含所有6个元音(包括y)的单词.元音的字母顺序.例如,一个答案可能是这样的:Aerious(Aerious不会起作用,因为它没有ay).目前该计划不会返回任何文字.我不认为containsVowels方法是正确的.

public static void question11() {
    System.out.println("Question 11:");
    System.out.println("All words that have 6 vowels once in alphabetical order: ");
    String vowelWord = "";

    for (int i = 1; i< WordList.numWords(); i++) {
        if (containsVowels(WordList.word(i))) {       
            if (alphabetical(WordList.word(i))) {
                vowelWord = WordList.word(i);
                System.out.println(vowelWord);
            }
        }
    }

    return;
}

public static boolean alphabetical(String word) {
    int vowelPlaceA = 0;
    int vowelPlaceE = 0;
    int vowelPlaceI = 0;
    int vowelPlaceO = 0;
    int vowelPlaceU = 0;
    int vowelPlaceY = 0;

    for (int i …
Run Code Online (Sandbox Code Playgroud)

java

6
推荐指数
2
解决办法
2665
查看次数

为什么这个空白?

这来自我们老师给我们的一个单词库,我应该返回最长的单词,其中只包含键盘顶行的字符.目前它返回空白.请帮忙.

//What's the longest word only using the top row of the keyboard?      
   public static void Question6() {  

      String longestWordSoFar = " ";
      System.out.println("Question 6:");
      for(int i = 1; i < WordList.numWords(); i++) // check every word in wordlist
      {
          if(topRow(WordList.word(i))) { // if the length is greater than the previous word, replace it
          {  
              if(WordList.word(i).length() > longestWordSoFar.length())            
                  longestWordSoFar=WordList.word(i);
              }      
          }

      }
      System.out.println("longest word including top row: " + longestWordSoFar);
      System.out.println();
      return;
   }

public static boolean topRow(String word) {

       for(int …
Run Code Online (Sandbox Code Playgroud)

java

0
推荐指数
2
解决办法
97
查看次数

标签 统计

java ×2