Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Insert the missing code in the following code fragment. This fragment is ended t

ID: 3830643 • Letter: I

Question

Insert the missing code in the following code fragment. This fragment is ended to read an input file named dataIn.txt and write to an output file named dataout.txt. Explain your answer. public static void main (string [] args) throws FileNotFoundException {String inputFileName = "dataIn. txt"; String ouputFileName = "dataOut.txt"; File inputFile =_____; Scanner in = new File(input FileName); ...} Assuming that inputFile is a Scanner object used to read words from a text file fill in an expression to complete the following code segment, which counts the number of words in the file. Explain your answer. int count = 0 while (input File. hasNext ()) {String word = _____; count++;} System. out.println (count); Insert the missing code in the following code fragment. This fragment is intended to read all words from a text file. Explain your answer. File input File = new File ("data In.txt"); Scanner in = new Scanner (dataIn.txt); while (_____) {String input = in next (); System.out.println (input);}

Explanation / Answer

2) new File(inputFileName) --> This is the exact blank to be filled to read an input file and write to an output file.

3) inputFile.next() --> Here, the correct blank need to filled with " inputFile.next()". next() returns the next element in the iteration. So based on inputFile the next element get processed.

4) in.hasNext() ---> Here, the correct blank need to filled with " in.hasNext()". hasNext() function returns true if the iteration has more elements if not it returns false. While condition checks for the "true" or "false".