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
e-lub [12.9K]
3 years ago
7

Write a program that asks the user for the name of a file. The program should display the number of words that the file contains

. The file to test your program on is attached to the assignment folder. It is called Lorem.txt.
Engineering
1 answer:
Flura [38]3 years ago
3 0

Answer:

import java.io.*;

import java.util.Scanner;

public class CountWordsInFile {

   public static void main(String[] args) throws IOException {

       Scanner keyboard = new Scanner(System.in);

       System.out.print("Enter file name: ");

       String fileName = keyboard.next();

       File file = new File(fileName);

       try {

       

           Scanner scan = new Scanner(file);

           

           int count = 0;

           

           while(scan.hasNext()) {

               scan.next();

               count += 1;

           }

           scan.close();

           System.out.println("Number of words: "+count);        

       } catch (FileNotFoundException e) {

           System.out.println("File " + file.getName() + " not present ");

           System.exit(0);

       }

   }

}

You might be interested in
Takt time is the rate at which a factory must produce to satisfy the customer's demand. a)- True b)- False
laila [671]

Answer: a)True

Explanation: Takt time is defined as the average time difference between  the production of the two consecutive unit of goods by the manufacturer and this rate is matched with the demand of the customer. This is the time which is calculated to find the acceptable time for which the goods unit must be produced  by the factory to meet the needs of the customer. Therefore , the statement is true that takt time is the rate at which a factory must produce to satisfy the customer's demand.

6 0
3 years ago
(True/False) Unix is written in the C language. *<br> True<br> O False
Katarina [22]

Answer:

false

Explanation:

8 0
2 years ago
Read 2 more answers
Reduce the force F ij = + (2 5 ) kN to point A(2m,3m) that acts on point B( 3m,5m) - .
Alexxx [7]

Given :

Force, \vec{F}= (2\hat{i} + 5\hat{j})\ kN.

Force is acting at point A( 2 m, 3 m ) and B( 3 m, 5 m )

To Find :

The work done by force F .

Solution :

Displacement vector between point A and B is :

\vec{d} = (3-2)\hat{i} + (5-3)\hat{j}\\\\\vec{d} = \hat{i} + 2\hat{j}

Now, we know work done is given by :

W = \vec{F}.\vec{d}\\\\W= (2\hat{i} + 5\hat{j}).(\hat{i}+\hat{2j})\\\\W = (2\times 1) +( 5\times 2) \ kJ\\\\W = 12 \ kJ

W = 12000 J

Therefore, work done by force is 12000 J .

6 0
2 years ago
If a 9V battery produces a current of 3 A through a load, what is the resistance of the load
Elden [556K]

3 ohms hope this helps :D ❤

7 0
2 years ago
Read 2 more answers
A body whose velocity is constant has a. positive acceleration b. negative acceleration g. zero acceleration d. all of the above
adoni [48]

Answer:

option (c) is the correct answer which is zero acceleration.

Explanation:

It is given in the question that the velocity is constant.

Now,

the options are provided in relation to the acceleration.

We know,

acceleration is rate of change of velocity per unit time i.e

acceleration = \frac{dV}{dt}

since, the change in velocity is given to be zero,

thus, dV/dt = 0

hence,  

acceleration = 0

therefore, option (c) is the correct answer which is zero acceleration.

4 0
3 years ago
Other questions:
  • The following C program asks the user for two input null-terminated strings, each stored in uninitialized 100-byte buffer, and c
    6·1 answer
  • A furnace wall consisting of 0.25 m of fire clay brick, 0.20 m of kaolin, and a 0.10‐m outer layer of masonry brick is exposed t
    8·1 answer
  • A cylindrical bar of metal having a diameter of 20.9 mm and a length of 205 mm is deformed elastically in tension with a force o
    9·1 answer
  • Consider the two wood pieces that are connected by a velcro as indicated below. The block is subjected to a tension force P and
    6·2 answers
  • Suppose that the voltage is reduced by 10 percent (to 90 VV). By what percentage is the power reduced? Assume that the resistanc
    10·1 answer
  • The ampere draw of a 5000 watt electric heater used on 120 volts is
    12·1 answer
  • How to Cancel prescription
    12·1 answer
  • How can statistical analysis of a dataset inform a design process
    11·1 answer
  • PLS HURRYY!!!<br> Look at the image below
    10·1 answer
  • Shane's 100-watt radio draws 7 amps of current on a 120-volt circuit. What is the resistance in the radio?
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!