弗莱希指数问题(Java)
我正在写一个程序,用来计算一篇文章或一个字符串的弗莱希指数,并告诉学生理解所需的最低教育水平 应该发生的是一个人输入一个字符串,这个字符串需要计算,程序需要计算单词的数量和句子的数量,并遍历每个单词,计算单词中有多少音节,然后将其添加到总音节计数器中。计算音节的方法是计算单词中相邻元音的数量,例如“计算机”中的元音o、u和e有3个音节。但是,如果单词以字母e结尾,从总音节数中减去1,那么“Passage”有a、a和e,但是由于e在末尾,音节数是2 以下是我到目前为止得到的信息:弗莱希指数问题(Java),java,flesch-kincaid,Java,Flesch Kincaid,我正在写一个程序,用来计算一篇文章或一个字符串的弗莱希指数,并告诉学生理解所需的最低教育水平 应该发生的是一个人输入一个字符串,这个字符串需要计算,程序需要计算单词的数量和句子的数量,并遍历每个单词,计算单词中有多少音节,然后将其添加到总音节计数器中。计算音节的方法是计算单词中相邻元音的数量,例如“计算机”中的元音o、u和e有3个音节。但是,如果单词以字母e结尾,从总音节数中减去1,那么“Passage”有a、a和e,但是由于e在末尾,音节数是2 以下是我到目前为止得到的信息: // Impor
// Import scanner to get input from the user
import java.util.Scanner;
public class Flesch
{
public static void main (String [] args)
{
public static final double BASE = 206.835;
public static final double WORD_LENGTH_PENALTY = 84.6;
public static final double SENTENCE_LENGTH_PENALTY = 1.015;
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++;
}
}
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]) {
totalSyllables = totalSyllables + 1;
}
if (lastChar(passage) == 'E' || lastChar(passage) == 'e') {
totalSyllables = totalSyllables - 1;
} else {
break;
}
}
}
System.out.println ("There are " + totalSyllables + " syllables.");
input.close();
public static char lastChar (String aWord)
{
char aChar = aWord.charAt(aWord.length() - 2);
System.out.print (aChar);
return aChar;
}
/** Return true if the last character in the parameter word is
* a period, question mark, or exclaimation point, and false
* otherwise
**/
public static boolean sentenceEnd (String word)
{
if (lastChar(passage) == '.') {
return true;
} else if (lastChar(passage) == '?') {
return true;
} else if (lastChar(passage) == '!') {
return true;
} else {
return false;
}
}
double fleschIndex = BASE - WORD_LENGTH_PENALTY * (totalSyllables / totalWords) - SENTENCE_LENGTH_PENALTY * (totalWords / totalSentences);
if (fleschIndex > 100) {
educationLevel = "4th grader";
} else if (fleschIndex <= 100) {
educationLevel = "5th grader";
} else if (fleschIndex <= 90) {
educationLevel = "6th grader";
} else if (fleschIndex <= 80) {
educationLevel = "7th grader";
} else if (fleschIndex <= 70) {
educationLevel = "8th grader";
} else if (fleschIndex <= 60) {
educationLevel = "9th grader";
} else if (fleschIndex <= 50) {
educationLevel = "high school graduate";
} else if (fleschIndex <= 30) {
educationLevel = "college graduate";
} else if (fleschIndex < 0) {
educationLevel = "law school graduate";
}
System.out.println ("The Flesch idex is " + fleschIndex + ".");
System.out.println ("The text can be understood by a " + educationLevel + ".");
}
}
//导入扫描仪以从用户获取输入
导入java.util.Scanner;
公共级弗莱希
{
公共静态void main(字符串[]args)
{
公共静态最终双基=206.835;
公共静态最终双字长度惩罚=84.6;
公开静态最终两句话长度惩罚=1.015;
扫描仪输入=新扫描仪(System.in);
//为音节和单词声明变量
整数totalWords=0;
整数总音节=0;
//提示用户输入一段文字
System.out.println(“请输入一些文本:”);
字符串通道=input.nextLine();
//言语
对于(int i=0;i100){
教育水平=“四年级学生”;
}否则,如果(fleschIndex在我看来,你把你的方法搞混了
方法sentenceEnd和lastChar位于主方法内。这是不允许的。
它们必须在main方法之外,但在Flesch类内部。显然,您不熟悉基本的Java语法。我所说的“basic”实际上是指basic。找一本类似“编写第一个Java程序”的书,因为有人修复了你在这里的错误,对网站和你来说都是无用的。可能的重复,一些版主可以删除这个问题吗?