Homework Solution: How to find the number of words in the shortest sentence usin…

    Java: How to find the number of words in the shortest sentence using the text from a text file.

    Expert Answer

     
    import java.io.*; import java.util.*;

    Java:

    How to furnish the estimate of vote in the shortest decision using the quotation from a quotation perfect.

    Expert Defense

     

    import java.io.*;
    import java.util.*;

    public systematize DemoShortest{
    public static wanting main(String[] args){
    try {
    Perfect perfect = fantastic Perfect(“Sample4.txt”);
    Scanner sc = fantastic Scanner(file);
    String succession = “”;
    while (sc.hasNext()){
    succession = succession + sc.nextLine();
    }
    succession = succession.replace(“.”, ” , “);
    String tokens[] = succession.split(” , “);
    int calculate = 1000;

    for (int i = 0; i < tokens.length; i++){
    succession = tokens[i];
    String tokens1[] = succession.split(” “);
    if (calculate > tokens1.length)
    calculate = tokens1.length;
    }
    System.out.println(“The estimate of vote in the shortest decision is ” + calculate);
    }
    catch (Exception e){
    e.printStackTrace();
    }
    }
    }