1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
SVEN [57.7K]
3 years ago
13

Write a program that outputs the number of characters, words, and lines in the files that are supplied as command-line arguments

.
Computers and Technology
1 answer:
Dahasolnce [82]3 years ago
4 0
Public class Exercise_13 {

public static void main(String[] args) {

if (args.length != 1) {
System.out.println("Invalid arguments.");
System.out.println("Usage: java Chapter_12.Exercise_13 filename");
System.exit(1);
}
File filename = new File(args[0]);
if (!filename.exists()) {
System.out.println(filename + " does not exist.");
System.exit(2);
}

int characters = 0;
int words = 0;
int lines = 0;

try {
Scanner input = new Scanner(filename);
while (input.hasNext()) {
String s = input.nextLine();
lines++;
characters += s.length();
String[] split = s.split(" ");
for (String word : split) {
words++;
}
}

} catch (FileNotFoundException ex) {
ex.printStackTrace();
}

System.out.println("Characters: " + characters);
System.out.println("Words: " + words);
System.out.println("Lines: " + lines);


}
}
You might be interested in
What is one of the limitations of marketing in social media?.
klemol [59]

One of the limitation of the social media marketing is the risk of negative comments that can hamper the marketing strategy and certainly hamper the sales.

<h3>What is marketing?</h3>

Marketing can be defined as the advertising of the services or products into the market for making the end user aware about the product. There are various marketing tricks that can help in increasing the sales of the products or services.

Learn more about marketing, here:

brainly.com/question/13414268

#SPJ1

3 0
2 years ago
The document that is use in excel to store an work with data that's formatted in a pattern of a uniformly space horizontalal an
Neporo4naja [7]

Answer:

Spreadsheet.

Explanation:

Microsoft Excel is a software application or program designed and developed by Microsoft Inc., for analyzing and visualizing spreadsheet documents.

The document that is use in excel to store a work with data that's formatted in a pattern of uniformly spaced horizontalal and vertical lines is called a spreadsheet.

A spreadsheet can be defined as a file or document which comprises of cells in a tabulated format (rows and columns) typically used for formatting, arranging, analyzing, storing, calculating and sorting data on computer systems.

Additionally, workbooks are known as Microsoft Excel files. An Excel workbook can be defined as a collection of one or more charts and worksheets (spreadsheets) used for data entry and storage in an excel file. In order to create a project on Excel you will have to use a workbook.

5 0
3 years ago
Is it possible to have the present value of a future payment that is greater than the future payment (i.e. the present value is
asambeis [7]

Note that the present value always less than the future value and so Is it not possible to have the present value of a future payment that is greater than the future payment.

<h3>Can present value be greater than future cash flows?</h3>

The present value is known to be often less than the future value this is due to the reason that money has interest-earning rate on top of it.

So therefore, that base on the fact that as long as interest rates are positive, then the present value of a sum of money will have to be less than its future value.

Learn more about present value from

brainly.com/question/20813161

6 0
3 years ago
Martha is a healer, a healthcare provider, and an experienced nurse. She wants to share her daily experiences, as well as her 12
STALIN [3.7K]
The answer to the question is blog.
4 0
4 years ago
Read 2 more answers
You will include code that will validate all user input. If the user inputs an invalid value, the program will respond with an e
alukav5142 [94]

Answer:

See explanation (Program written in C++)

Explanation:

The question is incomplete as the invalid values were not included in the question.

However, to make the sense of it, I'll answer your question using the following conditions.

1. Invalid values include: Numbers less than 0 (See comments for explanations)

#include <iostream>

using namespace std;

int main() {

//This line declares num (for user input)

int num;

//The following iteration keeps repeating itself until a number greater than 0 is entered using do while loop

do{

//This line prompts user for input

cout<<"Numbers greater than 0: ";

//This line gets input from the user

cin>>num;}

while(num<1);//This condition checks for valid user input

cout<<"You entered: "<<num; //This line prints out the user input

}

2. Invalid values include: Odd Numbers

I'll make use of the above code (in 1)

Start by replacing:

cout<<"Numbers greater than 0: ";

with

cout<<"Even Numbers: "; //This prompts user for even numbers

Replace

while(num<1);

with

while(num%2==1); //This checks if input is odd. If yes, the loop is repeated

3. Invalid values include: Even Numbers

I'll make use of the above code (in 1)

Start by replacing:

cout<<"Numbers greater than 0: ";

with

cout<<"Odd Numbers: "; //This prompts user for Odd numbers

Replace

while(num<1);

with

while(num%2==0); //This checks if input is even. If yes, the loop is repeated

8 0
3 years ago
Other questions:
  • What is the meaning of "At work, I am quite reserved."?
    15·2 answers
  • THE bestValue PROBLEM Using the Camera structure defined in file p1.cpp, write the function named bestValue(). The function take
    13·1 answer
  • One way to describe the note-taking tool eNotes is to call it an electronic notebook. electronic sticky note. online web clippin
    5·2 answers
  • Hey hope you are having a great day. Please subscribe to me on You tube at (Resurgentz). :)
    13·1 answer
  • A_______is a limitation imposed on the engineer. It can be a limitation on
    5·1 answer
  • Your laptop donot have a serial port. what type of connector will your laptop requireyour laptop donot have a serial port what t
    7·1 answer
  • Boolean, integer, string, and float are examples of:
    9·2 answers
  • c) If you are at foreign country visit, which banking card would you prefer to keep with you during visit (Debit Card or Credit
    10·1 answer
  • Is a mainframe computer portable?​
    10·1 answer
  • when you arrived at the unit today and listened to the change of shift report, you heard about a patient named jane w. according
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!