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]
3 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]3 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
When you are ready to print your document, what tab and command should you choose from the menu?
Margaret [11]

Answer:

File, Print UWU

Explanation:

3 0
3 years ago
Read 2 more answers
Add definitions for the following keywords to your glossary of words.
lianna [129]

Answer:

wifi=a facility allowing computers, smartphones, or other devices to connect to the internet or communicate with one another wirelessly within a particular area.

bandwidth=a range of frequencies within a given band, in particular that used for transmitting a signal.

The bit is the most basic unit of information in computing and digital communications. The name is a contraction of binary digit. The bit represents a logical state with one of two possible values. These values are most commonly represented as either "1" or "0", but other representations such as true/false, yes/no, +/−, or on/off are commonly used.

A megabit is a unit of digital information with prefix mega (symbol M). And it is equal to one million bits. It also means 106 bits or 1,000,000 bits. ... The unit symbol of megabit is Mbit. You can convert megabit to other units of data using our tool.

The gigabit is a multiple of the unit bit for digital information or computer storage. ... 1 gigabit = 109bits = 1000000000bits. The gigabit has the unit symbol Gbit or Gb. Using the common byte size of 8 bits, 1 Gbit is equal to 125 megabytes (MB) or approximately 119 mebibytes (MiB).

The Emergency Broadband Benefit is an FCC program to help families and households struggling to afford internet. The Emergency Broadband Benefit is limited to one monthly service discount and one device discount per household.

Buffering is the process of preloading data into a reserved area of memory that's called a buffer. In the context of streaming video or audio, buffering is when the software downloads a certain amount of data before it begins playing the video or music.

5 0
2 years ago
g What field in the IPv4 datagram header can be used to ensure that a packet is forwarded through no more than N routers? When a
ad-work [718]

Answer:

a) Time to live field

b) Destination

c) Yes, they have two ip addresses.

d) 128 bits

e) 32 hexadecimal digits

Explanation:

a) the time to live field (TTL) indicates how long a packet can survive in a network and whether the packet should be discarded. The TTL is filled to limit the number of packets passing through N routers.

b) When a large datagram is fragmented into multiple smaller datagrams, they are reassembled at the destination into a single large datagram before beung passed to the next layer.

c) Yes, each router has a unique IP address that can be used to identify it. Each router has two IP addresses, each assigned to the wide area network interface and the local area network interface.

d) IPv6 addresses are represented by eight our characters hexadecimal numbers. Each hexadecimal number have 16 bits making a total of 128 bits (8 × 16)  

e) IPv6 address has 32 hexadecimal digits with 4 bits/hex digit

4 0
2 years ago
Software is the brain of computer. Explain this starement
Annette [7]

here you go

i hope this helps you

5 0
3 years ago
Help meeeeeeeeeeeeeee please​
bija089 [108]

Answer:

Explanation:My explanation is above my comment :)

3 0
3 years ago
Other questions:
  • A _____________ is a method of controlled entry into a facility and provides access to secure areas such as a research lab or da
    10·1 answer
  • 13. You're expecting an important call from Mr. Suarez, a potential customer. While waiting for this call, your supervisor calls
    15·1 answer
  • Write a program that generates two 3x3 matrices, A and B, withrandom values in the range [1, 100] and calculates the expression½
    11·1 answer
  • 5. Drawing Conclusions If you were a person in
    10·1 answer
  • Does anyone know the point of gradpoint?
    8·1 answer
  • What would be a good hash code for a vehicle identification that is a string of numbers and letters of the form “9x9xx99x9xx9999
    9·1 answer
  • Space cushion includes
    8·2 answers
  • 50 ) What is the cell address of 4th row and 4th column? A) 4D B) E4 оооо C) 04 D) B4​
    9·1 answer
  • You are making a game! The player tries to shoot an object and can hit or miss it. The player starts with 100 points, with a hit
    13·1 answer
  • Which of the following best describes a balanced reaction
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!