Question: Use the method you created in the first part to flip the array in the file in the second part, storing the values into a

Use the method you created in the first part to flip the array in the file in the second part, storing the values into a new String[] called finalized. HELP!

import java.util.Arrays;

import java.io.File;

import java.io.FileNotFoundException;

import java.util.Scanner;

public class assignment4 {

private static String[] flipArray(String[] arr) {

String[] flipArray = new String[arr.length];

for (int i = 0; i < arr.length; ++i) {

flipArray[i] = arr[arr.length - i - 1];

}

return flipArray;

}

public static void main(String[] args) {

String[] array = {"A", "B", "C"};

System.out.println(Arrays.toString(flipArray(array)));

String output = "";

Scanner userInput = new Scanner(System.in);

System.out.print("Please enter a file name: ");

String fileName = userInput.nextLine();

File inputFile = new File(fileName);

try {

Scanner sc = new Scanner(inputFile);

while (sc.hasNextLine()) {

output += sc.nextLine() + " ";

}

sc.close();

} catch (FileNotFoundException e) {

System.err.println("File not found, please try again");

} finally {

userInput.close();

}

System.out.println(output);

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!