Flesch Index程序Java

时间:2014-09-22 23:20:39

标签: java

我正在编写这个程序来计算Java中段落的Flesch索引。一些事情:我无法弄清楚如何将它输入到你可以输入尽可能多的单词,同时按下输入,它将无法计算(像d告诉它不再有输入)。我也遇到了这个布尔表达式的问题。我试过&和&&它仍然无法正常工作。我不断收到一条消息,上面写着“令牌上的语法错误”&&“,抛出预期”

import java.util.Scanner;

public class Flesch
{
  public static void main (String [] args)
  {
    Scanner input = new Scanner (System.in);

    // Declare variables for syllables and words
    int totalWords = 0;
    int totalSyllables = 0;

    // Prompt user for a passage of text
    System.out.println ("Please enter some text:");
    String passage = input.nextLine();

    // Words
    for (int i = 0; i < passage.length(); i++)
    {
      if (passage.charAt(i) == ' ') {
        totalWords++;
      }
      else if (passage.charAt(i) == '.') {
        totalWords++;
      }
      else if (passage.charAt(i) == ':') {
        totalWords++;
      }
      else if (passage.charAt(i) == ';') {
        totalWords++;
      }
      else if (passage.charAt(i) == '?') {
        totalWords++;
      }
      else if (passage.charAt(i) == '!') {
        totalWords++;
      }
      else {
        totalWords = totalWords;
      }
    } 

    System.out.println ("There are " + totalWords + " words.");

    char syllableList [] = {'a', 'e', 'i', 'o', 'u', 'y'};

    // Syllables
    for (int k = 0; k < syllableList.length; k++)
    {
      for (int i = 0; i < passage.length(); i++)
      {
        if (passage.charAt(i) == syllableList[k]) && (passage.charAt(i) == syllableList[k]); {
          totalSyllables = totalSyllables;
        }
        if (passage.charAt(i) == syllableList[1] + ' ') {
          totalSyllables = totalSyllables;
        }
        if (passage.charAt(i) == syllableList[k]) {
          totalSyllables++;
        } else {
          totalSyllables = totalSyllables;
        }
      }
    }    
    System.out.println ("There are " + totalSyllables + " syllables.");
  }
}

我知道我必须输入计算,但是现在我只是想让它计算单词和音节的数量。一旦这个工作,我将添加计算以找到Flesch索引。谢谢你的帮助。出于某种原因,我在

行上出现错误
if (passage.charAt(i) == syllableList[k]) && (passage.charAt(i) == syllableList[k]);

我不知道为什么我会得到这个或如何解决它。

0 个答案:

没有答案