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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started