java中输入一段英文文章,请统计出该文章中的冠词数有多少个.
来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/09/29 21:58:05
java中输入一段英文文章,请统计出该文章中的冠词数有多少个.
输入一段英文文章,请统计出该文章中的冠词数有多少个。
英文中的冠词是指a、an和the
输入一段英文文章,请统计出该文章中的冠词数有多少个。
英文中的冠词是指a、an和the
package play;
import java.util.Scanner;
public class Test2 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入一段文章:");
String source = sc.nextLine();
System.out.println(source);
int aCount = statCount(source, "a");
int anCount = statCount(source, "an");
int theCount = statCount(source, "the");
System.out.println("这段文章中,冠词个数为:" + aCount + anCount + theCount);
}
private static int statCount(String source, String express) {
int count = 0;
if ((source.startsWith(express + " ") && source.length() > 2)) {
count++;
}
if ((source.endsWith(" " + express) && source.length() > 2)) {
count++;
}
String temp = source;
String _express = " " + express + " ";
int site = temp.indexOf(_express);
while (site != -1) {
count++;
temp = temp.substring(site + 1, temp.length());
site = temp.indexOf(_express);
}
return count;
}
}这么简单的代码,不需要解释,看得懂的吧。
import java.util.Scanner;
public class Test2 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入一段文章:");
String source = sc.nextLine();
System.out.println(source);
int aCount = statCount(source, "a");
int anCount = statCount(source, "an");
int theCount = statCount(source, "the");
System.out.println("这段文章中,冠词个数为:" + aCount + anCount + theCount);
}
private static int statCount(String source, String express) {
int count = 0;
if ((source.startsWith(express + " ") && source.length() > 2)) {
count++;
}
if ((source.endsWith(" " + express) && source.length() > 2)) {
count++;
}
String temp = source;
String _express = " " + express + " ";
int site = temp.indexOf(_express);
while (site != -1) {
count++;
temp = temp.substring(site + 1, temp.length());
site = temp.indexOf(_express);
}
return count;
}
}这么简单的代码,不需要解释,看得懂的吧。
java中输入一段英文文章,请统计出该文章中的冠词数有多少个.
c语言:统计单词.要求读取一个英文文章,文章内有数字,空格,标点符号等,请统计出该文章中单词的个数,注意单词只有全部有字
java求助。。。。有一篇文章,共有3行文字,每行有80个字符。要求分别统计出其中英文大写字母,小写字母,中文字母,中文
(求高手)java程序 :统计一篇文章中一共出现了多少个单词并且排序
有一篇文章,共有3行文字,每行最多不超过80个字符,请分别统计出其中英文大写字母、小写字母、数字、空格
有一英文文章,vb编程统计出26个字母中,出现频率最高的前5个字母,不区分大小写
C语言编程——输入一段英文,统计其中有多少个字母,单词和句子.
求VB程序代码 统计输入的一篇英文文章中的单词数和定冠词the的个数,并将出现的定冠词the全部删除
用java 编写一个程序,接受用户输入的一段英文文字,统计出其中的字符个数、单词个数和句子的个数.
请问用JAVA如何从一篇英文文章中,提取出所有的单词?
C问题,请赐教。有一篇文章,共有3行文字,每行有80个字符,要求分别统计出其中英文大写字母、小写字母、数字、空格以及其他
C语言题:有一篇文章,共有3行文字,每行有80个字符.编写程序分别统计出其中英文大写字母、英文小写字母