《C#程序设计》or《Java程序设计》第一次作业:源代码计算器

来源:互联网 发布:falcon猎鹰手表知乎 编辑:程序博客网 时间:2024/05/17 22:03
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];elsestrFileName = "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 ++;elsecodeLine ++;   }sc.close();totalLine = emptyLine+commentLine+codeLine;System.out.println("总行数="+totalLine);System.out.println("空行数="+emptyLine);System.out.println("注释行数="+commentLine);System.out.println("代码行数="+codeLine);}}

0 0
原创粉丝点击