Professional Documents
Culture Documents
i had to create a program that asks user to input sentences and then displays the
number of sentences.
so i worked on the program and this is what the main part of my code looks like:
{
c = new Console ();
String word;
int punctuation=userInput.length;
{
c.println ("the number of sentences are");
c.println ((counter+userInput.length ()));
the problem: after running it and entering a sentence the code stops.
i need help with correcting the part in my for loop.
i will appreciate any help
Thanks alot!
Word count
import java.io.*;
long numChar = 0;
long numLine=0;
long numWords = 0;
String line;
do{
line = in.readLine();
if (line != null){
numChar += line.length();
numWords += wordcount(line);
numLine++;
}while(line != null);
}
private static void linecount(String fileName){
BufferedReader in = null;
try{
in = new BufferedReader(fileReader);
linecount(fileName,in);
catch(IOException e){
e.printStackTrace();
long numWords = 0;
int index = 0;
char c = line.charAt(index++);
numWords++;
prevWhiteSpace = currWhiteSpace;
return numWords;
}
public static void main(String[] args){
long numChar = 0;
long numLine=0;
String line;
try{
if (args.length == 0)
line = in.readLine();
numChar = line.length();
if (numChar != 0){
numLine=1;
}else{
linecount(args[i]);
catch(IOException e){
e.printStackTrace();
}
}