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
Write a program that asks the user to enter a list of numbers. The program should take the list of numbers and add only those nu
pshichka [43]

In python 3.8

nums = input("Please enter a list of numbers: ").split()

new_nums = [x for x in nums if 0 < float(x) < 100]

print("The numbers between 0 and 100 are: " + " ".join(new_nums))

When you said numbers between 0 and 100, I didn't know if that was inclusive or exclusive so I made it exclusive. I hope this helps!

4 0
3 years ago
"A computer architect redesigns the pipeline above to enable branch prediction. When PCSrc is asserted (branch taken) IF/ID is f
Sindrei [870]

Answer:

Explanation:

Find attach the solution

3 0
3 years ago
Who can work on a fixed ladder that extends more than 24 feet?
baherus [9]

Answer:

Explanation:

If the fixed ladder will reach more than twenty-four (24) feet above a lower level, you as the employer are required to incorporate a personal fall arrest or ladder safety system into the installation of the ladder. For reference, this requirement is cited in OSHA Section 1910.28(b)(9)(i).

If the total length of the climb on a fixed ladder equals or exceeds 24 feet (7.3 m), the ladder must be equipped with ladder safety devices; or self-retracting lifelines and rest platforms at intervals not to exceed 150 feet (45.7 m); or a cage or well and multiple ladder sections with each ladder section not

plz mark as brainliest

8 0
3 years ago
Lately, you have noticed some repetitive stress in your wrist. Which sign is most likely the cause of that stress and pain?
Cerrena [4.2K]
1, you might have been carrying things that are way too heavy for you.
2, you might have weak tendons.
3 0
3 years ago
How can I skip more helppppppppppppppppppppppp
AfilCa [17]

Answer: skip what

Explanation:

4 0
3 years ago
Read 2 more answers
Other questions:
  • What will happen in a wire drawing operation when the cross-sectional area has a reduction of 60% in a single pass?
    10·1 answer
  • Suppose an underground storage tank has been leaking for many years, contaminating a groundwater and causing a contaminant conce
    8·1 answer
  • What is the function of engineering
    6·1 answer
  • Determine the force in members FD and DB of the frame. Also, find the horizontal and vertical components of reaction the pin at
    15·1 answer
  • What is the friction factor for fully developed flow in a circular pipe where Reynolds number is 1000
    6·1 answer
  • What can you add to a seatbelt ??<br> HELP ASAP
    15·1 answer
  • A proposed embankment fill requires 7100 ft of compacted soil. The void ratio of the compacted fill is specified as 0.5. Four bo
    10·1 answer
  • Who has the authority to declare a "global emergency"?​
    10·2 answers
  • Hi I'm trying to build a desk that moves up and down electrically but i need help
    9·1 answer
  • The sum of forces on node 2 (upper-left) is ______.
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!