Question: This week assignment is from file processing. Read a file Count number of lines Count number of words Count number of characters I have written

This week assignment is from file processing.

Read a file

Count number of lines

Count number of words

Count number of characters

I have written a Java program that can read the words of the file but I was stuck finishing it up can somebody help me finish up the code? here is the code that I wrote. I want to add a code that can count the number of characters and number of lines in my code. thank you

import java.util.*;

import java.io.*;

public class Assignment {

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

Scanner input = new Scanner(new File("am.txt"));

while(input.hasNextLine()) {

String line = input.nextLine();

Scanner ScanLine = new Scanner(line);

int count =0;

while (ScanLine.hasNext()) {

String word = ScanLine.next();

count++;

}

System.out.println("Line has " + count + " words");

}

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!