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
Urgent help<br> Write a program that prints ‘Hello World’ to the screen
lapo4ka [179]
Class newprog
 { 
      public static void main()
       {

                 System.out.println("Hello world");
              }
}
4 0
3 years ago
Write a destructor for the CarCounter class that outputs the following. End with newline.
ycow [4]

Answer:

Following are the code to this question:

CarCounter::~CarCounter()//Defining destructor CarCounter

{

cout << "Destroying CarCounter\n";//print message Destroying CarCounter

}

Explanation:

Following are the full program to this question:

#include <iostream>//Defining header file

using namespace std;

class CarCounter //Defining class CarCounter

{

public:

CarCounter();//Defining constructor CarCounter

~CarCounter();//Defining destructor CarCounter

private:

int carCount;//Defining integer variable carCount

};

CarCounter::CarCounter()//declaring constructor  

{

carCount = 0;//assign value in carCount variable

return;//using return keyword

}

CarCounter::~CarCounter()//Defining destructor CarCounter

{

cout << "Destroying CarCounter\n";//print message Destroying CarCounter

}

int main() //Defining main method

{

CarCounter* parkingLot = new CarCounter();//Defining class object parkingLot

delete parkingLot;//

return 0;

}

  • In the given C++ language code, a class "CarCounter" is defined, and inside the class, a "constructor, Destructors, and an integer variable" is defined.  
  • Outside the class, the scope resolution operator is used to define the constructor and assign value "0" in the integer variable.  
  • In the above-given code, the scope resolution operator, to define destructor and inside this cout function is used, which prints a message.  
  • In the main method, the class object is created, which automatically calls its class constructor and destructors.  
7 0
3 years ago
An attacker gained remote access to a user's computer by exploiting a vulnerability in a piece of software on the device. The at
Anni [7]

"A Buffer overflow" vulnerability exploit resulted from the attacker's actions.

Whenever a software or an application writes too much data into a buffer, causing neighboring storage regions to have been corrupted as a consequence, this could be determined as Buffer overflow.

⇒ There are two kinds of Buffer overflow attacks such as:

  • <u>Stack-based</u> - It will become more popular to use such memory, as well as that's only available during implementation of any code.
  • <u>Heap-based</u> - Those attacks seem to be more difficult to execute because they entail overflowing overall storage capacity allotted for a program further than the space needed for something like the program's present activities.

Thus we can say that the correct answer is a Buffer overflow.

Learn more about Buffer overflow here:

brainly.com/question/4952591

6 0
2 years ago
Notes on secondary memory​
gladu [14]

Answer:

non-volatile and persistent in nature

7 0
3 years ago
A .jpg file is an example of which of the following file types
egoroff_w [7]
A .jpg file is going to be a picture. =)
5 0
3 years ago
Read 2 more answers
Other questions:
  • if your instructors teaching style is very different from your learning preference your best choice is to one work on your weake
    10·1 answer
  • Which attribute of the image tag specifies the URL of an image
    14·1 answer
  • which three objects can be linked or embedded in a word document? A. worksheets, margins, colors B. charts, worksheets, images C
    7·1 answer
  • Which person would be the best fit for a career in the Information Technology field?
    6·2 answers
  • Kellyn needs to move Slide 8 of his presentation up so that it becomes Slide 6. What best describes how he can do this using the
    11·2 answers
  • JAVA CODE.
    6·1 answer
  • Activity 1.1.4 What is Technology?
    10·1 answer
  • What impact download speeds on different computers
    13·1 answer
  • Wirte a program which asks the users to input length and calculates the area of a square.( Area = Length^2)​
    14·1 answer
  • Hellpppppppppppppppp
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!