Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Given a file where each line is a single (32-bit) integer, read in the lines of the file one at a time; for each value

Given a file where each line is a single (32-bit) integer, read in the lines of the file one at a time; for each value i=0,..., v-1, output all lines that are == i mod v in reverse order from their order in the file, where v>0 is the value of the last line. For example, if the input is 6 0 mod 3 2 2 mod 3 4 1 mod 3

10 1 mod 3 2 2 mod 3 9 0 mod 3 3 v = 3, 0 mod 3 since v=3 we will output the lines that are 0 mod 3 then 1 mod 3 then 2 mod 3; within each such group we reverse the order from the input file: 3 9 6 10 4 2 2

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 CES316Q4 {

/**

* 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL Instant Reference

Authors: Gruber, Martin Gruber

2nd Edition

0782125395, 9780782125399

More Books

Students also viewed these Databases questions

Question

What is the main difference between internal energy and heat?

Answered: 1 week ago