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

Write a method named reportBlankLines that accepts a Scanner containing an input

ID: 3909979 • Letter: W

Question

Write a method named reportBlankLines that accepts a Scanner containing an input file as a parameter and that outputs the line numbers of any blank lines and that reports the total number of blank lines in the file. For example, given the following input file:

Your method should print the following output:

Notice that each blank line produces a line of output and that there is a final line of output reporting the total number of blank lines. Also notice that lines are numbered starting with 1 (the first line is line 1, the second line is line 2, and so on). If the input has no lines or no blank lines, output the following:

Explanation / Answer

import java.util.Scanner; public class BlankLines { public static void reportBlankLines(Scanner fin) { int i = 1, count = 0; while (fin.hasNextLine()) { if(fin.nextLine().isEmpty()) { System.out.println("line " + i + " is blank"); count++; } i++; } System.out.println("total blank lines = " + count); } }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote