Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
902 B
1
Indexable
Never
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);
                
    }
}
Leave a Comment