Print the number of lines the number of words

Assignment Help JAVA Programming
Reference no: EM13165734

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

Line 1 has 5 tokens (longest = 11) 
Line 2 has 8 tokens (longest = 6) 
Line 3 has 6 tokens (longest = 6) 
Line 4 has 3 tokens (longest = 13) 
Longest line : the jaws that bite, the claws that catch,

im getting :

Line 1 has 5 tokens (longest = 11) Line 1 has 8 tokens (longest = 6) Line 1 has 6 tokens (longest = 6) Line 1 has 3 tokens (longest = 13)

 

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

 

 

Reference no: EM13165734

Questions Cloud

Example for processor scheduling : Give a (specific) example for processor scheduling in which preemption helps improve performance. Now discuss the feasibility of designing a preemptive disk scheduling algorithm for a disk read workload in which each job has the same priority. Do ..
Define get and set functions and two constructors : Create a class called Building. It will have one data member of type string (used for a postal address). Define get and set functions and two constructors.
State what is the kinetic energy of an electron : Electrons are ejected from sodium metal by any light that has a wavelength shorter than 544 nm. What is the kinetic energy of an electron
Mick''s wicks makes candles in various sizes : Mick's Wicks makes candles in various sizes. Create a class for the business named Candle that contains data fields for color, height, and price. Create get methods for all three fields
Print the number of lines the number of words : a java program where im supposed to print the number of lines the number of words and the longest line in a text file!
The stack-based routing scheme : the stack-based routing scheme you are to have a stack of maze locations.
Create a sequentially numbered array : Create a sequentially numbered array of 50 integers. Then use the Random_range procedure to shuffle the array in a random order.(Each number will only appear once in the array.) Display the shuffled array.
Write vhdl code to compile the greatest common divisor : Write VHDL code to compite greatest common divisor of two integers using Euclidean algorithm
State electrons are ejected from sodium metal by any light : Electrons are ejected from sodium metal by any light that has a wavelength shorter than 544 nm. What is the kinetic energy of an electron

Reviews

Write a Review

JAVA Programming Questions & Answers

  Write a program that reads in a list of numbers from a file

write a program that reads in a list of numbers from a file and adds up all those numbers. You may hard code in the name of the file, allowing the user to input the filename is not required

  One-dimensional array to solve the

In C#, Use a one-dimensional array to solve the following problem. A company pays its salespeople on a commission basis. The salespeople each receive $200 per week plus 9 percent of their gross sales for that week. For example, a salesperson who gros..

  Three most primary forms of loops: the while loop, the do..

explored the world of loops we have accepted the three most primary forms of loops: the while loop, the do...while loop (even though Python does not use this loop), and the for loop. The for loop has approximately three primary implementations that w..

  Application that generates a quiz

Create an application that generates a quiz. Prompt for the user's first and last name, college major, and confidence in test taking (high, medium, or low). The quiz should contain at least five true/false questions about horticulture. When the user ..

  Record managing system application

Build a student record managing system application

  Write a program that converts number from binary to decimal

write a program that Converts a Number from Binary to Decimal  by using reading keyboard input.

  Modify the book class to accommodate multiple authors

modify the Book class to accommodate multiple authors using one of the components from the Java Collection Framework.

  Define private instance variable to hold boolean value

Write a Java Enumeration "LetterGrade" that represents letter grades A through F including plus and minus grades. Define a private instance variable to hold a boolean value.

  Determine product a inferior or normal good

Research illustrates that prices of related goods are given by Py = $5,900 and ; Pz = $90, while average income of individuals consuming this product is M = $55,000. Is X inferior or normal good?

  Implementation of memory management

Implementation of memory management

  Program to translates a number into the closest letter grade

Write a program that translates a number into the closest letter grade. For example, the number 2.8 (which might have been the average of several grades) would be converted to B-. Break ties in favor of the better grade

  A java program that will prompt the user to input a file

Write a Java program that will prompt the user to input a file (document) in order to count the frequency of each word. This program will display the frequency of each word sorted alphabetically or by frequency (depending on the preference of the use..

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd