Untitled
unknown
plain_text
a year ago
902 B
6
Indexable
import java.io.File; import java.util.Scanner; public class blankspace { public static void main(String[] args) throws Exception{ File myfile = new File("C:\\Users\\student\\Documents\\NetBeansProjects\\first\\src\\first\\sample.txt"); Scanner scan = new Scanner(myfile); int totalBlanks = 0 , numberOfLine = 0; while(scan.hasNextLine()){ String data = scan.nextLine(); numberOfLine++; int size = data.length(); for(int i = 0 ;i < size ; i++){ if(Character.isWhitespace(data.charAt(i))){ totalBlanks++; } } } System.out.println("Number of spaces is: " + totalBlanks); System.out.println("Number of Lines is :" + numberOfLine); } }
Editor is loading...
Leave a Comment