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

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!