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]
4 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]4 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
10. Technician A says checking the automatic
Naya [18.7K]

Answer: a

Explanation:

4 0
3 years ago
Dcfxvfsvcfsfvfssvdaeeaew
Ainat [17]

Answer:

meepus weepus

Explanation:

8 0
3 years ago
Read 2 more answers
What is the De Broglie wavelength of an electron under 150 V acceleration?
yanalaym [24]

Answer:

0.1 nm

Explanation

Potential deference of the electron is given as V =150 V

Mass of electron m=9.1\times 10^{-31}

Let the velocity of electron = v

Charge on the electron =1.6\times 10^{-19}C

plank's constant h =6.67\times 10^{-34}

According to energy conservation eV =\frac{1}{2}mv^2

v=\sqrt{\frac{2eV}{M}}=\sqrt{\frac{2\times 1.6\times 10^{-19}\times 150}{9.1\times 10^{-31}}}=7.2627\times 10^{-6}m/sec

Now we know that De Broglie wavelength \lambda =\frac{h}{mv}=\frac{6.67\times 10^{-34}}{9.1\times 10^{-31}\times 7.2627\times10^6 }=0.100\times 10^{-9}m=0.1nm

4 0
3 years ago
Read 2 more answers
Question 1 : Replacement [42 Pts] Consider the following page reference string:
MakcuM [25]

Answer:

Optimal

Time 123456789101112

RS. ecbeagdcegda

F0. eeeeeeeee e e a

F1 c c c c c c c c c c c

F2 b b b g g g g g g g

F3 a a d d d d d d

Page fault? * * * * * * *

Total page fault:7

2. LRU

Time 1 2 3 4 5 6 7 8 9 10 11 12

RS e c b e a g d c e g d a

F0 e e e e e e e c c c c a

F1 c c c c g g g g g g g

F2 b b b b d d d d d d

F3 a a a a e e e e

Page fault? Y Y Y N Y Y Y Y Y N N Y Total page fault:9

3. LRU approximation algorithm: Second chance

Time 1 2 3 4 5 6 7 8 9 10 11 12

RS e c b e a g d c e g d a

F0 0,e 0,e 0,e 1,e 1,e 0,e 0,e 0,e 1,e 1,e 1,e 0,e

F1 0,c 0,c 0,c 0,c 0,g 0,g 0,g 0,g 1,g 1,g 0,g

F20,b0,b0,b0,b0,d0,d0,d0,d1,d0,dF30,a0,a0,a0,c0,c0,c0,c0,a

Page fault? YYYNYYYYNNNY

Total page fault: 8

4 0
3 years ago
Read 2 more answers
Technician A states that air tools generally produce more noise than electric tools, so wear ear protection when using air tools
dusya [7]

Answer:

Both Technician A and Technician B are correct

Explanation:

Air tools and electric tools are both power tools as they are used to make work easier. Air tools generally use an air compressor that powers the motor of the tool making it possible to use it while electric tools as the name implies are powered by an electric source which in this case is batteries. An example of an air tool is the nail gun which can be used by furniture makers to drive nails and they are often louder than electric tools because of vibrations caused by the compressor making it necessary to use ear protection when using the tool for ear safety.

Technician B  is also correct because it is always advisable to use impact sockets while using impact guns due to the ability of the impact sockets to withstand the force caused by operating impact guns and make work neater when nuts and bolts are being loosened or tightened.

5 0
3 years ago
Other questions:
  • A socket can be driven using any of the following except for (A) a socket ratchet
    14·1 answer
  • The distribution of actual weights of 8‑ounce wedges of cheddar cheese produced at a dairy is Normal, with mean 8.1 ounces and s
    5·1 answer
  • The entrance of the space module into atmosphere is one of the very critical phases of any space mission. Due to the formation o
    6·1 answer
  • Steam enters a turbine operating at steady state at 800°F and 450 lbf/in^2 and leaves as a saturated vapor at 1.2 lbf/in^2. The
    12·1 answer
  • Oxygen combines with nitrogen in the air to form NOx at about
    6·2 answers
  • Ordan has _ 5 8 can of green paint and _ 3 6 can of blue paint. If the cans are the same size, does Jordan have more green paint
    15·1 answer
  • A 550 kJ of heat quantity needed to increase water temperature from 32°C to 80°C. Calculate the mass
    8·1 answer
  • Sơ đồ nguyên lý của một hệ thống lạnh
    11·1 answer
  • MANUFACTURING QUESTION PLEASE HELP​
    11·1 answer
  • Derive the expression ε=ln(1+e), where ε is the true strain and e is the engineering strain. Note that this expression is not va
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!