![eagles2286](/avatars/45246.jpg)
eagles2286
09.11.2020 •
Computers and Technology
Assume a file containing a series of integers is named numbers.txt and exists on the computer’s disk. Write a program that calculates the average of all the numbers stored in the file.
Solved
Show answers
More tips
- C Computers and Internet How to Format Your C Drive: Detailed Guide and Tips...
- F Food and Cooking How to Properly Cook Buckwheat?...
- F Food and Cooking How Many Grams Are In a Tablespoon?...
- L Leisure and Entertainment Carving: History and Techniques for Creating Vegetable and Fruit Decorations...
- P Photography and Videography How to Choose the Perfect Photo Paper for Your Images?...
- H Health and Medicine What vaccines do children need?...
- H Health and Medicine Reasons for the Appearance of Warts: Everything You Need to Know...
- A Art and Culture How to Learn Screaming: Step-by-Step Guide for Beginners...
- H Health and Medicine Contraceptive Pills After 35: The Importance Of Choosing The Right Medication...
- C Computers and Internet How to Choose a Monitor?...
Answers on questions: Computers and Technology
- C Computers and Technology Is there a gpa requirement to start online schooling...
- C Computers and Technology Bm jus like dati gtg to school...
- B Biology What are the differences between active transport and passive transport...
- M Mathematics Solve for X: -2(6x+4)=88. Answer fast please...
- S Social Studies La palabra tambien se llama...
- E English Why did Dove renamed her grandmother Beulah in Dusting? And what lines in the poem show that?...
- M Mathematics What is the area in square feet of the rectangle 4 3/4 6 4/5...
- M Mathematics PLZ HELP WILL BE GIVING BRAINLEIST (once im done with this)...
- H History In your opinion, what cause of WWI was most significant (important)? Explain in a short paragraph...
- M Mathematics I ve never made friends in my life and today I just made 3 great friends. Now what?...
Ответ:
Explanation:
The following code is written in Java. It assumes that the numbers.txt file is in the same folder as the Java file and the numbers are separated one on each line. It reads the file, adds all the numbers to an array, then adds the numbers into a single variable and finally divides by the total amount of numbers in order to get the average.
public static void main(String[] args) {
ArrayList<Integer> numbers = new ArrayList();
try {
File myObj = new File("numbers.txt");
Scanner myReader = new Scanner(myObj);
while (myReader.hasNextLine()) {
String data = myReader.nextLine();
numbers.add(Integer.parseInt(data));
}
myReader.close();
} catch (FileNotFoundException e) {
System.out.println("An error occurred.");
e.printStackTrace();
}
int average = 0;
for (int x:numbers) {
average += x;
}
average = average / numbers.size();
System.out.println(average);
}
Ответ:
D) spreadsheet.xls
Explanation:
Spreadsheet files end with common extensions such as XLSX or XLS.
.doc is for word documents
.html is for webpage files
.ppt is for powerpoints