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

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.