Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 sum modulo 240223 of every vth line starting from the last line, until youve summed ceil(n/2) lines, where n is the number of lines in the file, and v>0 is the value of the last line. If the file is empty, output 0. For example, if the input is 30 40 this is the is the second line we sum because its at index 5-4=1. 20 5 this is the third line we sum because its at index (5-8) wrapping around. 10 4 we start at the last line at index 5. This defines v=4 and n=6. then the output is 49, because (4 + 40 + 5)%240223 =49; since n=6 we will sum 3 lines, starting with the last, then 4th from the last, then 4th behind that, wrapping around.

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

/**

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

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

Students also viewed these Databases questions

Question

Can workers be trained in ethics? How? Defend your answer.

Answered: 1 week ago