ファイルから読み取った文字列から特定の文字とすべての整数を削除します。
目標は、スキャナーを介して読み取られている文字列から、文以外の末尾の文字と数字をすべてスクラブすることでした。これらの char と int を削除した理由は、読み込まれた単語から正確な単語数、文数、および音節数を生成するためでした。
元の投稿コードは非常にラフで、修正されており、私から以下に再投稿します。
いつもご協力いただきありがとうございます。
public class Word {
private int wordCount, sentenceCount, syllableCount;
private int nums [] = {1,2,3,4,5,6,7,8,9,0};
private char vowels [] = {'a', 'e', 'i', 'o', 'u', 'y'};;
private char punctuation [] = {'!', '?','.', ';', ':','-','"','(', ')'};;
public Word()
{
wordCount = 0;
sentenceCount = 0;
syllableCount =0;
}
public Word(String next)
{
if(next.length() > 1)
{
//
// Remove punctuation that does not create sentences
//
for(int i = 5; i < punctuation.length; i++)
for(int j = 0; j < next.length(); j++)
if(next.charAt(j) == punctuation[i])
next = next.replace(j, "");
//
// Counting Sentences
//
for(int i=0; i < 5; i++)
if(punctuation[i] == next.charAt(next.length()-1))
sentenceCount++;
//
// Remove numbers for accurate word counting
//
for(int i = 0; i < nums.length; i++)
for(int j = 0; j < next.length(); j++)
if(next.charAt(j) == nums[i])
next = next.replace(j, "");
//
// Counts all syllables
//
for(int i = 0; i < vowels.length; i++)
for(int j = 0; j < next.length()-1; j++)
if(vowels[i] == next.charAt(j))
syllableCount++;
System.out.println(next);
}
}