Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

im working on a java program where im supposed to print the number of lines the

ID: 3552557 • Letter: I

Question

im working on a java program where im supposed to print the number of lines the number of words and the longest line in a text file!

i just need help printing the longest line of my text...

and with the number of lines.. my keep printin 1 in each line :

insted of 1, 2, 3, 4 the number of words and the number of letter in the longest word are ok !



Beware the Jabberwock, my son,
the jaws that bite, the claws that catch,
Beware the JubJub bird and shun
the frumious bandersnatch.


my output should be


This is my cod e


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

public class InputS{
   public static void main (String [] args )
   throws FileNotFoundException{

      Scanner console = new Scanner ( System.in);
      System.out.println(" ");
      System.out.println();
      System.out.println("Please enter a name of a file " );
      String name = console.nextLine();
      Scanner input = new Scanner ( new File (name));
      while (input.hasNextLine()) {
         String line = input.nextLine();
         inputStats(new Scanner(line));


      }



   }//end of amin
   public static void inputStats (Scanner input)
       throws FileNotFoundException{
      int numLines=0;
      int numwords=0;
      int letter=0;
      String maxword = "";
      String maxLine= "";


      while (input.hasNext()){

         String next = input.next();// number of tokes
         numwords++;

         if (next.length() > maxword.length()) {// longest word

                     maxword = next;
                  }

}//end of while

while ( input.hasNextLine()){// line numbers
    String Lines =input.nextLine();
numLines++;
}







System.out.print("Line " + numLines + " has ");
System.out.print( numwords + " tokens " );
System.out.print("(longest = " + maxword.length()+ ")");




System.out.println();


   }//end of method

}// end of class

Explanation / Answer