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
Kitty [74]
4 years ago
7

Write a program that reads a file name from the keyboard. The file contains integers, each on a separate line. The first line of

the input file will contain the number of integers in the file. You then create a corresponding array and fill the array with integers from the remaining lines. If the input file does not exist, give an appropriate error message and terminate the program. After integers are stored in an array, your program should call the following methods in order, output the intermediate results and count statistics on screen, and at end output even integers and odd integers to two different files called even.out and odd.out.
Implement the following methods in the program:
* public static int[] inputData() – This method will ask user for a file name, create an array, and store the integers read from the file into the array. If input file does not exist, give an appropriate error message and terminate the program.
* public static void printArray(int[] array) – This method will display the content of the array on screen. Print 10 integers per line and use printf method to align columns of numbers.
public static void reverseArray(int[] array) – This method will reverse the elements of the array so that the 1st element becomes the last, the 2nd element becomes the 2nd to the last, and so on.
* public static int sum(int[] array) – This method should compute and return the sum of all elements in the array.
* public static double average(int[] array) – This method should compute and return the average of all elements in the array.
* public static int max(int[] array) – This method should find and return the largest value in the array.
* public static int min(int[] array) – This method should find and return the smallest value in the array.
* public static void ascendingSelectionSortArray(int[] array) – This method will use Selection Sort to sort (in ascending order) the elements of the array so that the 1st element becomes the smallest, the 2nd element becomes the 2nd smallest, and so on.
* public static void desendingBubbleSortArray(int[] array) – This method will Bubble Sort to sort (in descending order) the elements of the array so that the 1st element becomes the largest, the 2nd element becomes the 2nd largest, and so on.
* public static void outputData(int[] array) – This method will create two output files called even.out and odd.out. Scan through the entire array, if an element is even, print it to even.out. If it is odd, print the element to odd.out.
Computers and Technology
1 answer:
Sindrei [870]4 years ago
4 0

Answer:

Explanation:

import java.util.Scanner;

import java.io.*;

public class ArrayProcessing

{

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

{

Scanner kb = new Scanner(System.in);

String fileName;

System.out.print("Enter input filename: ");

fileName = kb.nextLine();

File file = new File(fileName);

if(!file.exists())

{

System.out.println("There is no input file called : " + fileName);

return;

}

int[] numbers = inputData(file);

printArray(numbers);

}

public static int[] inputData(File file) throws IOException

{

Scanner inputFile = new Scanner(file);

int index = 1;

int size = inputFile.nextInt();

int[] values = new int[size];

while(inputFile.hasNextInt() && index < values.length)

{

values[index] = inputFile.nextInt();

index++;

}

inputFile.close();

return values;

}

public static void printArray(int[] array)

{

int count = 1;

for (int ndx = 1; ndx < array.length; ndx++)

{

System.out.printf("%5.f\n", array[ndx]);

count++;

}

if(count == 10)

System.out.println("");

}

}

You might be interested in
Open a command prompt on PC1. Issue the command to display the IPv6 settings. Based on the output, would you expect PC1 to be ab
Strike441 [17]

Answer:

yes it can communicate with all interfaces on the router.

Explanation:

PC1 has the right default gateway and is using the link-local address on R1. All connected networks are on the routing table.

Netsh may be a Windows command wont to display and modify the network configuration of a currently running local or remote computer. These activities will tell you in how manny ways we can use the netsh command to configure IPv6 settings.

To use this command :

1. Open prompt .

2. Use ipconfig to display IP address information. Observe the  output whether IPv6 is enabled, you ought to see one or more IPv6 addresses. A typical Windows 7 computer features a Link-local IPv6 Address, an ISATAP tunnel adapter with media disconnected, and a Teredo tunnel adapter. Link-local addresses begin with fe80::/10. ISATAP addresses are specific link-local addresses.  

3. Type netsh interface ipv6 show interfaces and press Enter. note the output listing the interfaces on which IPv6 is enabled. Note that each one netsh parameters could also be abbreviated, as long because the abbreviation may be a unique parameter. netsh interface ipv6 show interfaces could also be entered as netsh  ipv6 sh i.

4. Type netsh interface ipv6 show addresses  Observe the results  of the interface IPv6 addresses.

5. Type netsh interface ipv6 show destinationcache and press Enter. Observe the output of recent IPv6 destinations.

6. Type netsh interface ipv6 show dnsservers and press Enter. Observe the results listing IPv6 DNS server settings.

7. Type netsh interface ipv6 show neighbors and press Enter. Observe the results listing IPv6 neighbors. this is often almost like the IPv4 ARP cache.

8. Type netsh interface ipv6 show route and press Enter. Observe the results listing IPv6 route information.

5 0
3 years ago
30 POINTS!!
bulgar [2K]

Answer:

online

the answer is online

7 0
3 years ago
The qwerty keyboard is the most common layout of keys on a keyboard.
vagabundo [1.1K]
The qwerty keyboard is the most common keyboard.
6 0
4 years ago
Read 2 more answers
What is windows powershell? I downloaded a fake video game on my PC.(It was an accident) Now, powershell is bugging me. Is it a
IrinaVladis [17]

Answer:

The PowerShell is a kind of shell framework, which was being developed by Microsoft for covering various administrative tasks like the configuration automation and management of certain repetitive jobs. And the term 'PowerShell' does refer to both of these- and its the shell applied for executing commands, and scripting language.

And yes, you have been infected by the virus. You need to run the antivirus immediately.

Explanation:

Please check the answer section.

5 0
4 years ago
Read 2 more answers
Suppose h(m) is a collision-resistant hash function that maps a message of arbitrary bit length into an n-bit hash value. is it
Korolek [52]

That can't be true. Collision resistant just means the chance is really low, but not 0. Suppose you enumerate all possible hash values with each their different original message. Since the message length can be larger than n, you can then find a message whose hash is already in the list, ie., a collision!

5 0
3 years ago
Other questions:
  • What does SMTP stand for?
    6·2 answers
  • What is one characteristic of a logic problem? A). a problem that can have three solutions B). a problem that can be solved in a
    5·1 answer
  • If you are viewing a webpage with customized or regenerated content, such as updated stock quotes, what type of webpage are you
    14·1 answer
  • We are tall straight and upright who are we
    7·2 answers
  • Nearly all states allow citizens who are not able to go to the polls due to business travel to vote using this method: Internet
    9·2 answers
  • What is a nonlinear presentation?
    14·2 answers
  • How can these requirements be met? Universal Containers conduct evaluations of their sales reps using a custom object consisting
    10·1 answer
  • During executing of the ______ PR task, units regain control of IP and transfer physical custody to the reintegration team.
    6·1 answer
  • 30 POINTS! PLEASE ANSWER QUICK!!!
    12·1 answer
  • Class secretType { public: static int count; static int z; secretType(); secretType(int a); void print(); static void incrementY
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!