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

  An api for a library that provides for all these operations

Quaternions can be represented with four (4) real numbers (a,b,c,d). They can be added, subtracted, multiplied and divided. You can multiply a quaternion by a scalar (which produces a quaternion as a result)

  Write a program that assigns seats on an airplane

Prepare a program that teaches arithmetic to a young child. The program tests subtraction and addition. Write a program that assigns seats on an airplane.

  Java method that contains code to be executed

Write a short Java method that contains code for which it is probably impossible for that code to ever be executed, but your favorite Java compiler does not detect this fact.

  Write java program to display results in java applet

Write down the java program which displays following results in java applet. Permits the user to enter three numbers (use JOptionPane for this) and prints out average of those value on screen.

  Write java program to evaluate postfix expressions

Write a java program to evaluate postfix expressions containing complex numbers using a stack. This program should contain two classes.

  Create a complete java application

Create a complete Java application that meets these requirements and the program has an opening comments section (using block comments) with the file name, date, your name, and purpose of the program.

  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 the java application on web

Determine the Java application on Web and explain how program structure functions. Explain the application in as much detail as possible.

  Study the code and implement the operator overloading

The Table Q3 on the next page is the code of a class named Circle. Study the code and implement the operator overloading for these relational operators ( , >=) for the Circle class. Then, write a test program that creates two instances of the Circle ..

  Your letterinventory class must use an array

Your LetterInventory class must use an array of Counter objects. Note that there is no nextChar method in the Scanner class. You must use the next() method and then use a loop through the characters of the token that is returned. Ignore any character..

  Create system in java using agile approach

You are a software manager in company which designs critical control software for aircraft. Create system in Java using agile approach with a user involved in the development team.

  Design a java program that simulates a slot machine

Design a java program that simulates a slot machine. When the program runs, it should do the following: Ask the user to enter the amount of money he or she wants to insert into the slot machine. ? Instead of displaying images, the program will random..

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