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

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!