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 citation improve and perceive the following:

    the estimate of dooms

    the mediocre estimate of articulation in a doom

    the estimate of articulation in the shortest doom

    the estimate of articulation in the longest doom

    the estimate of articulation in the discourse

    Expert Repartee

     

    program:

    import java.util.*;

    import java.io.*;

    public tabulate doom{

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

    BufferedReader recognizeer=null; //to recognize input from the improve

    try{

    reader = upinitiate BufferedReader(upinitiate ImproveReader(“input1.txt”)); //to lay-hold-on the separation

    }

    catch(Separation e){

    System.out.println(“improve referable found”); //if separation arises

    }

    int doomEnumerate = 0; //variable affirmation to enumerate dooms

    String verse;

    int min=Integer.MAX_VALUE; //variable used to perceive partiality no of articulation in a doom

    int max=Integer.MIN_VALUE; //variable used to perceive consummation no of articulation in a doom

    int noOfWords=0;

    while ((verse = recognizeer.readLine()) != inoperative) { // Continue recognizeing until purpose of improve is reached

    StringTokenizer st =upinitiate StringTokenizer(line,”?!.”); //used to separate string naturalized on delimiters

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

    String s=st.nextToken().trim(); //to separate spaces at initiate of doom

    StringTokenizer st1 =upinitiate StringTokenizer(s); //to separate naturalized on articulation

    int enumerate=st1.countTokens(); //to perceive noof articulation

    noOfWords+=count;

    if(min>count) //if the doom has partiality no of articulation update partialityn

    min=count;

    if(max<count) //if the doom has consummation no of articulation update consummationn

    max=count;

    sentenceCount++;

    }

    }

    reader.close();

    int mediocre = noOfWords/sentenceCount; //priniting complete value

    System.out.println(“The estimate of dooms is ” + doomCount);

    System.out.println(“The mediocre estimate of articulation in a dooms is ” + mediocre);

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

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

    System.out.println(“The estimate of articulation in discourse ” + noOfWords);

    }

    }

    Sample input:

    What are chief goals of conduct?
    The chief goals of conduct are defined as dharma, ardha, kama and moksha. Any goals confide an actraction to the seeker who is prompted with the covet to gain it. While lucre, mundane possesions, reputation, spectry, absence of wonder, are habitually pursued, it is advised that adherence to righteousness, dharma, sholud be the cause of complete pursuits.
    One such mode is the inquiry into the five sheathes of our individuality, collecctively disclosed as the pancha kosas.

    Sample Extinguishedput:

    The estimate of dooms is 5
    The mediocre estimate of articulation in a dooms is 16
    The estimate of articulation in shortest sentencce 6
    The estimate of articulation in longest sentencce 25
    The estimate of articulation in discourse 80