Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 {
// 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 outputStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started