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 you've 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 it's at index 5-4=1.
20
5 ←this is the third line we sum because it's 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 execute{

     public static void execute(BufferedReader r, PrintWriter w)

    /**
     * @param r the reader to read from
     * @param w the writer to write to
     * @throws IOException, NumberFormatException
     */

    }

}

     

 

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_2

Step: 3

blur-text-image_3

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

Auditing and Assurance services an integrated approach

Authors: Alvin a. arens, Randal j. elder, Mark s. Beasley

14th Edition

133081605, 132575957, 9780133081602, 978-0132575959

More Books

Students also viewed these Databases questions

Question

What other requirements do they have for admission?

Answered: 1 week ago