Question: public static void execute(BufferedReader r, PrintWriter w) throws IOException, NumberFormatException { // TODO(student): Your code goes here. w.println(-1); } in java Part 1. [10 marks]

 public static void execute(BufferedReader r, PrintWriter w) throws IOException, NumberFormatException {

public static void execute(BufferedReader r, PrintWriter w) throws IOException, NumberFormatException {

// TODO(student): Your code goes here.

w.println(-1);

}

in java

Part 1. [10 marks] 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 each line (other than the first) that is a multiple of its previous line. For example, if the input is 398240224firstlinehasnopreviousline;wedontincludeitever9isamultipleof3,soweaddittooursum8isnotamultipleof9,sowedontincludeit240224isamultipleof8,soweaddittooursum Then the output is 10 , since (9+240224)%240223=10. Be careful of integer overflow: if x+y> Integer.MAX_VALUE then x+y will (incorrectly) be a negative number. Use the mathematical properties of mod highlighted above to avoid such overflow (note that (9%240223+240224%240223)%240223=(9+1)%240223=10%240223=10). For more examples, see the tests in the tests/ directory that have the form lab1-p1-X-in.txt for the input, and the matching lab1-p1-X-out.txt for the expected output

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!