import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class A {
public static void main(String[] args) throws FileNotFoundException {
int totalLine = 0;
int emptyLine = 0;
int commentLine = 0;
int codeLine = 0;
String strFileName;
if(args.length>=1)
strFileName = args[0];
else
strFileName = "src/A.java";
Scanner sc = new Scanner(new File(strFileName));
while (sc.hasNextLine()) {
String strTmp = sc.nextLine();
strTmp = strTmp.trim();
if(strTmp.length()==0)
emptyLine ++;
else if(strTmp.length()>2 && "//".equals(strTmp.substring(0,2))==true)
commentLine ++;
else
codeLine ++;
}
sc.close();
totalLine = emptyLine+commentLine+codeLine;
System.out.println("总行数="+totalLine);
System.out.println("空行数="+emptyLine);
System.out.println("注释行数="+commentLine);
System.out.println("代码行数="+codeLine);
}
}
《C#程序设计》or《Java程序设计》第一次作业:源代码计算器
最新推荐文章于 2020-11-25 22:13:20 发布