Question
Write a program to read from a file “input4_01.txt” an integer N (0≤ N ≤ 100) and then read N double numbers from this file to an array. Write to file “output4_01.txt” the maximum number of the array. For example
File: “input4_01.txt”
5
1.30 2.22 4.00 17.60 3.14
File “output4_01.txt”
17.60
Question2: Write a program to read from a file “input4_02.txt” an integer N (0≤ N ≤ 100) and then read N double numbers from this file to an array. Write to file “output4_02.txt” this array but in the reverse order and also the sum of all elements in the array. For example
File: “input4_02.txt”
5
1.30 2.22 4.00 17.60 3.14
File “output4_02.txt”
3.14 17.60 4.00 2.22 1.30
Sum = 28.26
Solution Preview
This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.
import java.io.File;import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.util.Scanner;
public class Question1 {
public static void main(String[] args) throws FileNotFoundException, UnsupportedEncodingException
{
PrintWriter writer = new PrintWriter("output4_01.txt", "UTF-8");
Scanner input = new Scanner(new File("input4_01.txt"));
int count = input.nextInt();
double[] nums = new double[count];
double max = 0;
for(int i = 0; i < count; i++)
{...