For example, if I have the following lines of text in a file:
this is an example. this is an example.
this is an example. this is an example. this is an example
this is an example this is an example this is an example this is an example this is an example this is an example this is an example this is an example this is an example this is an example.
I want to be able to count these lines as 3 paragraphs. Now my code will count this as 4 paragraphs, as it does not know when a paragraph begins and ends.
Scanner file = new Scanner(new FileInputStream("../.../output.txt"));
int count = 0;
while (file.hasNextLine()) { //whilst scanner has more lines
Scanner s = new Scanner(file.nextLine());
if(!file.hasNext()){
break;
}
else{
file.nextLine();
count++;
}
s.close();
}
System.out.println("Number of paragraphs: "+ count);
file.close();
This is what I have so far. It reads lines of text, and treats each line as a single paragraph.
I want it to treat lines of text that don't have any empty line between them as 1 paragraph and count all paragraphs in file.