CMPINF 401 XTRA CREDIT #3
The Assignment: WORTH 1 POINT COURSE CREDIT (SAME AS A LAB)
NO PARTIAL CREDIT. IT'S ALL/NOTHING
YOU ARE NOT ALLOWED TO USE: Set<> or HashSet<> or TreeSet<> or Map<> or HashMap<> or TreeMap<>
You are NOT allowed to sort the array, you are not allowed to pass the array into any function. You are only allowed to write ONE LOOP that visit the elements of the array ONCE. HINT: using jsut that one loop you shyould cal the min, max, and sum of the elements in the array, Once you have the sum, figure out what the sum would have been if the number was not missing. The difference between those two numbers tells what the missing number is.
This Extra Credit assignment asks you to read in a file with several lines. Each line of the file represents the sequence lo .. hi inclusive EXCEPT one of the interior numbers is missing and the numbers appear in random order. I give you all the code that reads each line of the file into an array. That array is passed into a method you must write. The method is allowed to loop over the array ONCE and then do a few arithmentic operation to determine what the missing number is. That method is returned back to main and printed by me. Look at both the input file and the file containing the expected/correct output. Your solution must loop over the array only once.
In fact, you are only allowed to look at each element of the array ONE TIME!
ALL OR NOTHING. NO PARTIAL CREDIT. WORKS PERFECTLY OR GETS A ZERO
RUN IT LIKE THIS ===> java MissingNumber XC3input.txt
You only fill in the one method at the bottom. No other code to write.
7 12 15 11 14 9 13 8
4 11 5 10 6 9 8
31 41 33 40 32 38 35 37 36 34
18 24 15 23 16 17 22 21 13 20 19
The exact (and only) 4 lines of output your program must produce
must look EXACTLY like this and there must be no blank lines outputted.
7 12 15 11 14 9 13 8 missing 10
4 11 5 10 6 9 8 missing 7
31 41 33 40 32 38 35 37 36 34 missing 39
18 24 15 23 16 17 22 21 13 20 19 missing 14