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]
2 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]2 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
The page that appears when you first open your Internet browser is the _____.
Leni [432]

Answer:home page

Explanation:

7 0
2 years ago
How to charge your phone quickly
stepladder [879]
I found out that putting your phone on airplane mode will charge it faster
4 0
3 years ago
Read 2 more answers
The term packet is used fairly generically to refer to protocol data unit (PDU). There are PDU equivalent names in the different
Westkost [7]

Answer:

Bits

Explanation:

The protocol data unit is the representative unit of data in the OSI layer of a network. The OSI system has seven layers.

The physical layer is the first layer of the system and the protocol data unit is represented as bits of data.

Note that the term packet is the PDU for data in the network layer of the OSI network system.

4 0
2 years ago
50 points for each person brainless goes to the best answer
wolverine [178]

Technical writing is writing that is done for the purpose of educating, informing or directing someone on how to do something. Technical writing is significantly different than other types of writing such as narrative, because technical writing is intended to impart to the reader some specific skill or ability. Technical writing isn't for everyone. It is often very detail-oriented and usually involves writing within fields where some advanced knowledge is required. When given a technical writing assignment, it also must be approached in a certain way in order for you to be successful. but i would have to go with c- e commerce

6 0
3 years ago
Read 2 more answers
Which loan type requires you to make loan payments while you’re attending school?
Levart [38]
<span>A:Unsubsidized federal loan</span>
7 0
3 years ago
Other questions:
  • . String literals are surrounded by _____ quotes
    14·1 answer
  • The space force enhancement function concerned with providing data on meteorological, oceanographic, and space environmental fac
    12·1 answer
  • What is the result when you run the following program?
    12·1 answer
  • 27. List four advantages of Computer Aided Design over traditional hand
    10·1 answer
  • The company where Derek works has tasked him with setting up and securing a SOHO router. He wants to make sure the wireless netw
    7·1 answer
  • What happens when a dataset includes records with missing data?
    9·1 answer
  • Explain the role of a computer in education​
    9·1 answer
  • The technology dealing with robots is called
    6·1 answer
  • Jason is working on a Microsoft Excel worksheet and he wants to create a Print Preview shortcut. His teacher asks him to access
    9·1 answer
  • 1 point
    5·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!