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

  Recursive factorial program

Write a class Array that encapsulates an array and provides bounds-checked access. Create a recursive factorial program that prompts the user for an integer N and writes out a series of equations representing the calculation of N!.

  Hunt the wumpus game

Reprot on Hunt the Wumpus Game has Source Code listing, screen captures and UML design here and also, may include Javadoc source here.

  Create a gui interface

Create GUI Interface in java programing with these function: Sort by last name and print all employees info, Sort by job title and print all employees info, Sort by weekly salary and print all employees info, search by job title and print that emp..

  Plot pois on a graph

Write a JAVA program that would get the locations of all the POIs from the file and plot them on a map.

  Write a university grading system in java

University grading system maintains number of tables to store, retrieve and manipulate student marks. Write a JAVA program that would simulate a number of cars.

  Wolves and sheep: design a game

This project is designed a game in java. you choose whether you'd like to write a wolf or a sheep agent. Then, you are assigned to either a "sheep" or a "wolf" team.

  Build a graphical user interface for displaying the image

Build a graphical user interface for displaying the image groups (= cluster) in JMJRST. Design and implement using a Swing interface.

  Determine the day of the week for new year''s day

This assignment contains a java project. Project evaluates the day of the week for New Year's Day.

  Write a java windowed application

Write a Java windowed application to do online quiz on general knowledge and the application also displays the quiz result.

  Input pairs of natural numbers

Java program to input pairs of natural numbers.

  Create classes implement java interface

Interface that contains a generic type. Create two classes that implement this interface.

  Java class, array, link list , generic class

These 14 questions covers java class, Array, link list , generic class.

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