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
What can you do to stop a computer from repeatedly restarting in a continuous loop?
abruzzese [7]
There are ways to break into the boot cycle of every machine, you could use one of them. Hold down modifier key[s] so that it boots differently or you may get a menu to select boot options.

A specific answer is OS/firmware dependent.
4 0
3 years ago
Write the pseudocode for this flowchart
MrMuchimi

Answer:

Explanation:

class TimeToSleep() {

  main bunch of stuff (string argos) {

       int age;

       string comedy;

       bool guess;

        public bool imTheMasterMethod() {

           guess = true;

           while (guess) {

              comedy = "You forgot to put the flowchart, you meathead!";

              println(comedy);

               

                scan("%d", &age);

                if (age < 18) {

                    println("Go to sleep kiddo!");

                }

           }

        }

   }

}

       

6 0
2 years ago
Explain how the number of jobs available to workers has been affected by the use of ICT in commerce and industry, using specific
blondinia [14]

Answer:

The main cause of lack of jobs is due to automation and the ability for computers to do everything faster, more efficiently and effectively.

Explanation:

A specific example - Data entry jobs are redundant from automation programs

- Economic Forum predicted a net increase of 58 million jobs for automation, so this accounts for losses but isn't case specific to data entry

6 0
2 years ago
How do I turn on your asus chromebook flip?
galben [10]
I believe the charger has to be connected for it to turn on.
3 0
3 years ago
Write the function lettersOnly(s) that takes in a string called s, and returns a string containing only the alphabetic character
Phantasy [73]

Answer:

The program to this question as follows:

Program:

def lettersOnly(s): #defining method lettersOnly

   val="" #defining string variable that return value

   for i in s: #defining loop to calculate value

       if(i.isalpha()): #check condition that value is string

           val=val+ i #add value

   return val #return value

print(lettersOnly("data3base_ro1c3k5s")) #call method and print value

Output:

databaserocks

Explanation:

In the above python code, a method lettersOnly is declared that accepts a string variable  "s" in its parameter. Inside the method, a string variable "val", and loop is declared, in which the "val" variable holds method return value.

  • In the loop and if block is used that uses "isalpha" string method, which checks the check alphabetic character in the given value. if this is true it will calculate all value in "val" variable and return its value.    
  • At the last, the print method is used, which calls the lettersOnly method and prints its return value.
4 0
3 years ago
Other questions:
  • What are the three main purposes of an operating system? Explain how the old mainframe computers were different from the compute
    12·1 answer
  • What event in the 1970s contributed to the current
    6·2 answers
  • Suppose alice, with a web-based e-mail account (such as hotmail or gmail), sends a message to bob, who accesses his mail from g
    10·1 answer
  • From your computer you are able to establish a telnet connection to a remote host but a traceroute to the host IP address result
    6·1 answer
  • Select the correct answer.
    10·1 answer
  • Use the function random.randint to write a program that rolls a 6-sided die 100 times, and prints out all of the rolls.
    8·1 answer
  • What department is cyber security
    6·2 answers
  • What is python, the coding language
    6·2 answers
  • Q3: What do you mean by a pointer to a pointer? Can this be extended?
    10·1 answer
  • What are the nuclear codes?
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!