•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Java section within the Software Development category of DaniWeb, a massive community of 456,197 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,943 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Java advertiser: Lunarpages Java Web Hosting
Views: 457 | Replies: 1
![]() |
•
•
Join Date: May 2007
Posts: 5
Reputation:
Rep Power: 0
Solved Threads: 0
I need help in figuring out how to make the code for sentences by determining that there is ., ?, ! in the sentence at the end. And the paragraph where you find each paragraph by the spaces between the lines. If you could just help me start, I'll finish it...
scanner = new Scanner(new File("C://README.txt"));
while (scanner.hasNext())
{
String input = scanner.nextLine();
StringTokenizer tokenizer = new StringTokenizer(input);
charCount = charCount + input.length();
lineCount = lineCount + 1;
while (tokenizer.hasMoreTokens())
{
word = tokenizer.nextToken();
wordCount = wordCount + 1;
for( int i = 0; i < input.length(); i++ )
{
if( Character.isLetter(input.length()) == true )
{
charPerWordCount = charPerWordCount + 1;
}
}//end Character Per Word
for( int k = 0; k < input.length(); k++ )
{
if( Character.isWhitespace('\r') == true )
{
paragraphCount = paragraphCount + 1;
}
}// end Paragraph
}//end StringTokenizer
}// end Scanner
scanner.close();
// print out statistics
System.out.println( "Page count: " + lineCount/60 );
System.out.println( "Word count: " + wordCount );
System.out.println( "Line Count: " + lineCount );
System.out.println( "Character count: " + charCount );
System.out.println( "Character per word count: " + charPerWordCount );
System.out.println( "Sentence count: " + sentenceCount );
System.out.println( "Paragraph count: " + paragraphCount );
}
}//end TextFileStats.java
scanner = new Scanner(new File("C://README.txt"));
while (scanner.hasNext())
{
String input = scanner.nextLine();
StringTokenizer tokenizer = new StringTokenizer(input);
charCount = charCount + input.length();
lineCount = lineCount + 1;
while (tokenizer.hasMoreTokens())
{
word = tokenizer.nextToken();
wordCount = wordCount + 1;
for( int i = 0; i < input.length(); i++ )
{
if( Character.isLetter(input.length()) == true )
{
charPerWordCount = charPerWordCount + 1;
}
}//end Character Per Word
for( int k = 0; k < input.length(); k++ )
{
if( Character.isWhitespace('\r') == true )
{
paragraphCount = paragraphCount + 1;
}
}// end Paragraph
}//end StringTokenizer
}// end Scanner
scanner.close();
// print out statistics
System.out.println( "Page count: " + lineCount/60 );
System.out.println( "Word count: " + wordCount );
System.out.println( "Line Count: " + lineCount );
System.out.println( "Character count: " + charCount );
System.out.println( "Character per word count: " + charPerWordCount );
System.out.println( "Sentence count: " + sentenceCount );
System.out.println( "Paragraph count: " + paragraphCount );
}
}//end TextFileStats.java
![]() |
•
•
•
•
•
•
•
•
DaniWeb Java Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Other Threads in the Java Forum
- Previous Thread: <b>TextFileStats.java need help!</b>
- Next Thread: Display



Linear Mode