Question: Write a Java method that will take an array of integers of size n and shift right by m places, where n > m. You
Write a Java method that will take an array of integers of size n and shift right by m places, where n > m. You should read your inputs from a file and write your outputs to another file. Create at least 3 test cases and report their output.
I've created a program to read and write to separate files but i don't know how to store the numbers from the input file into an array and then store the new shifted array into an output file.
****MY CODE*****
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.Scanner;
public class shiftedArray {
public static void main(String[] args) throws FileNotFoundException {
File input = new File("inputFile.txt");
// this is main file to read from
PrintWriter output = new PrintWriter("OutputFile.txt");
//printwriter writes to the new file outputFile.txt
Scanner sc = new Scanner(input); //scans input file
//while loop to loop all lines from main file
while(sc.hasNextLine()) {
output.println(sc.nextLine());
}
//close scanner of input file and close new file output
sc.close();
output.close();
// TODO Auto-generated method stub
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
