Question
Given a file where each line is a single (32-bit) positive integer, read in the lines of the file one at a time; output the
Given a file where each line is a single (32-bit) positive integer, read in the lines of the file one at a time; output the lines that are divisible by the previous line, in reverse order. For example, if the input is 4 2 not divisible by the previous line 8 divisible by 2, so we output 8 8 divisible by 8, so we output 8 The output is therefore 8 8
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.List;
import java.util.ArrayList;
import java.util.Deque;
import java.util.ArrayDeque;
import java.util.Iterator;
public class CSE316 {
/**
* Read lines one at a time from r. Outputs to w according to the
* lab specifications.
* Assumes every line is an integer; otherwise it throws a NumberFormatException.
* @param r the reader to read from
* @param w the writer to write to
* @throws IOException, NumberFormatException
*/
public static void execute(BufferedReader r, PrintWriter w) throws IOException, NumberFormatException {
// TODO(student): Your code goes here.
w.println(-1);
}
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