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); } }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.