Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is my code for intro to java programming problem 12.13 and i dont know how to fix this 12.13 (Count characters, words, and lines

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

This is my code for intro to java programming problem 12.13 and i dont know how to fix this

"12.13 (Count characters, words, and lines in a file) Write a program that will count the number of characters, words, and lines in a file. Words are separated by whitespace characters. The file name should be passed as a command-line argument, as shown in Figure 12.13 . Command Prompt exercise>java Exercise12_13 Loan.java ile Loan.java has 1919 characters 210 words 71 lines c:Texercise Figure 12.13 The program displays the number of characters, words, and lines in the given file. 9package javaapplication12.pkg13; 10 import java.util.*; 11 L import java.io.*; 12 13 kk 14 15 16 public class JavaApplication1213 { 17 18 19 20 21 /kok @param args the command line arguments k @throws java. lang.Exception public static void main(String[] args) throws Exception 23 24 25 26 27 28 29 30 31 32 /TODO code application logic here //12.13 if (args.length !- 1) System.out.println("Command-line argument is missing!") System.exit(1); String fileName = args [0]; File source = new File(fileName); 34 if (source.exists()) System.out.println(fileName +"file does not exist!"); System.exit(2); 35 36 37 38 39 40 41 42 Scanner infile - new Scanner(source); String line; int charactersCount -0; int wo rd sCount = 0; int linesCount0 45 46 while(infile.hasNextLine()); 48 49 50 51 52 53 54 line - infile.nextLine); linesCount++ String[ wordsline.split(""); wordsCount words.length; for(String token words) 56 57 58 59 60 61 62 63 64 65 charactersCount token.length); System.out.println( "Name of the input file:"+ fileName); System.out.println("Number of lines in the file:"inesCount); System.out.println( "Number of words in the file" + wordsCount) System.out.println("Number of characters in the file:"charactersCount) 67 Output - JavaApplication12.13 (run) run: Command-line argument is missing! BUILD FAILED (total time: 0 seconds) Users/Caitlyn/Library/Caches/NetBeans/8.2/executor-snippets/run.xml:53: Java returned: 1

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

=+221 .1 Answered: 1 week ago

Answered: 1 week ago

Question

explain what is meant by experiential learning

Answered: 1 week ago

Question

identify the main ways in which you learn

Answered: 1 week ago