public class Computesourceline {public static void main (string[] args) throws FileNotFoundException {//TODO auto-generate D method stub//defines the relevant variable int totalline = 0;int Emptyline = 0;int Commentline = 0;int CodeLine = 0;//We all focus on the scanner class (network search) and The use of the string class (textbook P75 and the Network)//path to the file string strfilename;//using the command line, if there is a command line argument, the file name is obtained from the outside world, otherwise the specified file//usage is used: Java Computesourceline filename (replaces filename with the full file name in practice) if (args.length>=1) strFileName = Args[0];elsestrfilename = "src/ Computesourceline.java ";//Read file with Scanner Scanner sc = new Scanner (new file (strFileName)); while (Sc.hasnextline ()) { String strtmp = Sc.nextline ();//Remove the space before and after strtmp = Strtmp.trim ();//Determine whether it is a blank line, comment, line of code if (Strtmp.length () ==0) Emptyline + +; else if (strtmp.length () >2 && "//". Equals (Strtmp.substring (0,2)) ==true) Commentline ++;elsecodeline ++;// System.out.println (strtmp); }//off Sc.close (); totalline = Emptyline+commentline+codeline; SYSTEM.OUT.PRINTLN ("total number of rows =" +totalline); System.out.println ("Number of empty lines =" +emptyline); System.out.println ("Number of comment lines = "+commentline"); System.out.println ("line of code =" +codeline);}}
Given a source code file (. cs,. java), output the total number of rows in the file, the number of empty lines, the number of comment lines, the number of lines of code