Please fix this so that it prints out the word count instead of the character co
ID: 3647337 • Letter: P
Question
Please fix this so that it prints out the word count instead of the character count.import. java.util.*;
public class WordCount
{
public static void main(String[]args)
{
final int Lines=6;
Scanner in=new Scanner (System.in)
String paragraph = "";
System.out.println( "Please input"+ Lines + "lines of text.");
for (int i=0; i < Lines; i+=1)
{
paragraph=paragraph+""+in.nextLine()
}
System.out.println(paragraph);
System.out.println(paragraph.length());
String word=""
int WordCount=0
for (int i=0; i<paragraph.length()-1; i+=1)
{
if (paragraph.charAt(i) !==' ' OR paragraph.charAt(i) !==',' OR paragraph.charAt(i) !==';' OR paragraph.charAt(i) !==':' )
{
word= word + paragraph.charAt(i);
if(paragraph.charAt(i+1)==' ' OR paragraph.charAt(i) ==',' OR paragraph.charAt(i) ==';' OR paragraph.charAt(i) ==':')
{
System.out.println(word);
wordCount +=1
word="";
} //end if
} //end if
} //end for
} //end main
} //end class
Explanation / Answer
please rate - thanks
import java.util.*;
public class WordCount1
{
public static void main(String[]args)
{
final int Lines=6;
Scanner in=new Scanner (System.in);
String paragraph = "";
System.out.println( "Please input "+ Lines + " lines of text.");
for (int i=0; i < Lines; i+=1)
{
paragraph=paragraph+" "+in.nextLine();
}
System.out.println(paragraph);
String word="";
int WordCount=0;
for (int i=0; i<paragraph.length()-1; i+=1)
{
if (paragraph.charAt(i) != ' ' || paragraph.charAt(i) !=',' || paragraph.charAt(i) !=';' || paragraph.charAt(i) !=':' )
{
word= word + paragraph.charAt(i);
if(paragraph.charAt(i+1)==' ' || paragraph.charAt(i) ==','|| paragraph.charAt(i) ==';' || paragraph.charAt(i) ==':')
{
WordCount +=1;
word="";
} //end if
} //end if
} //end for
System.out.println("There are "+WordCount +" words ");
} //end main
} //end class