当前位置: 代码迷 >> Java面试 >> 软件工程师的代码量是怎么计算的?
  详细解决方案

软件工程师的代码量是怎么计算的?

热度:6   发布时间:2016-04-17 00:30:22.0
程序员的代码量是如何计算的???
经常看到有些网友提起程序员的代码量的问题,代码量怎么算呢?不能说我整天写System.out.println();写100,10000行就说我的代码量是100,10000了吧?什么样的代码才能算呢?
------解决方案--------------------

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

public class Files {

static long whiteLine = 0;
static long comentLine = 0;
static long sormaLine = 0;

public static void main(String[] args) {
File f = new File("填写路径,不用具体到文件名,只要路径下有.java文件就可以");
File[] codeFiles = f.listFiles();
for(File child:codeFiles){
//System.out.println(child);
preas(child);
}
System.out.println("空行:"+whiteLine);
System.out.println("注释行:"+comentLine);
System.out.println("有效行:"+sormaLine);
}

private static void preas(File f){
BufferedReader br = null;
Boolean comPd = false;
try {
br = new BufferedReader(new FileReader(f));
String readLine = null;
while((readLine = br.readLine())!=null){
readLine = readLine.trim();
if(readLine.matches("^[\\s&&[^\\n]]*$")){
whiteLine ++;
}else if(readLine.startsWith("/*")&&!readLine.endsWith("*/")){
comentLine ++;
comPd = true;
}else if(readLine.startsWith("/*")&&!readLine.endsWith("*/")){
comentLine ++;
}else if(comPd){
comentLine ++;
if(readLine.endsWith("*/")){
comPd = false;
}
}else if(readLine.startsWith("//")){
comentLine ++;
}else{
sormaLine++;
}
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

}



------解决方案--------------------
一般公司都是直接给你任务 你做好就行 没人管你代码量
比较正规的公司 会有SVN服务器 你们的代码都放到上面 各个员工每天的代码量一目了然
------解决方案--------------------
代码量不好计算的啊
因为你写的有效代码和无效代码不容易用程序来区分,但是这个计算的时候你又不可能让人去一点一点的看
所以代码量计算其实是一点意思都没有的
  相关解决方案