By far, I have written the code to find the lines of code in a program. I want to extend it to find the lines of code in a class and method...
import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.LineNumberReader; import java.util.Scanner; public class LinesOfCode { public static void main(String[] args) { try { BufferedReader reader= new BufferedReader(new FileReader ("C:\\Users\\Kalyani\\Documents\\NetBeansProjects\\HelloWorld\\src\\MeanStandardDeviation.java")); int totalLines=0; int emptyLines=0; String line=""; while((line=reader.readLine())!= null) { line=line.trim(); if(line.isEmpty()) { emptyLines++; continue; } totalLines++; } System.out.print("Total Lines : "+totalLines+" LOC\n"); System.out.print("Empty Lines : "+emptyLines+" LOC\n"); } catch(FileNotFoundException e) { System.out.print(e.getMessage()); } catch(Exception e) { System.out.print(e.getMessage()); } } }