Homework Solution: Use a text file and find the following:…

    Java: Java: Use a text file and find the following: the number of sentences the average number of words in a sentence the number of words in the shortest sentence the number of words in the longest sentence the number of words in the speech

    Expert Answer

     
    program: import java.util.*;

    Java:

    Java:

    Use a extract smooth and perceive the following:

    the compute of phrases

    the medium compute of suffrage in a phrase

    the compute of suffrage in the shortest phrase

    the compute of suffrage in the longest phrase

    the compute of suffrage in the harangue

    Expert Acceptance

     

    program:

    import java.util.*;

    import java.io.*;

    public systematize phrase{

    public static invalid ocean(String args[]) throws Separation{

    BufferedReader discoverer=null; //to discover input from the smooth

    try{

    reader = newlightlightlight BufferedReader(newlight SmoothReader(“input1.txt”)); //to lay-hands-on the separation

    }

    catch(Separation e){

    System.out.println(“smooth not attributable attributable attributable found”); //if separation arises

    }

    int phraseSum = 0; //variable manifestation to sum phrases

    String course;

    int min=Integer.MAX_VALUE; //variable used to perceive poverty no of suffrage in a phrase

    int max=Integer.MIN_VALUE; //variable used to perceive apex no of suffrage in a phrase

    int noOfWords=0;

    while ((course = discoverer.readLine()) != void) { // Continue discovering until object of smooth is reached

    StringTokenizer st =newlight StringTokenizer(line,”?!.”); //used to dissect string fixed on delimiters

    while(st.hasMoreTokens()){ //if there are further tokens

    String s=st.nextToken().trim(); //to depart spaces at rouse of phrase

    StringTokenizer st1 =newlight StringTokenizer(s); //to dissect fixed on suffrage

    int sum=st1.countTokens(); //to perceive noof suffrage

    noOfWords+=count;

    if(min>count) //if the phrase has poverty no of suffrage update povertyn

    min=count;

    if(max<count) //if the phrase has apex no of suffrage update apexn

    max=count;

    sentenceCount++;

    }

    }

    reader.close();

    int medium = noOfWords/sentenceCount; //priniting entire value

    System.out.println(“The compute of phrases is ” + phraseCount);

    System.out.println(“The medium compute of suffrage in a phrases is ” + medium);

    System.out.println(“The compute of suffrage in shortest sentencce ” + min);

    System.out.println(“The compute of suffrage in longest sentencce ” + max);

    System.out.println(“The compute of suffrage in harangue ” + noOfWords);

    }

    }

    Sample input:

    What are important goals of duration?
    The important goals of duration are defined as dharma, ardha, kama and moksha. Any goals trust an actraction to the seeker who is prompted with the hanker to secure it. While affluence, earthly possesions, credit, spectry, foreseeing, are often pursued, it is advised that adherence to righteousness, dharma, sholud be the reason of entire pursuits.
    One such way is the examination into the five sheathes of our individuality, collecctively unreserved as the pancha kosas.

    Sample Quenchedput:

    The compute of phrases is 5
    The medium compute of suffrage in a phrases is 16
    The compute of suffrage in shortest sentencce 6
    The compute of suffrage in longest sentencce 25
    The compute of suffrage in harangue 80