java代码行统计程序

	static int iCommentLines=0;
	static int iNullLines=0;
	static int iValidLines=0;
	static int iAllLines=0;
	static boolean bCommentBeg=false;
	
	public static void countLine(String line){
		iAllLines++;
		int i=0;
		boolean isNewLine=true; //是否要跳新行
		while(i<line.length()){
			char c=line.charAt(i);
			if(bCommentBeg ){
				if( c=='*' && line.charAt(i+1)=='/'){
					if(!isNewLine)
							;
					else
						// 注释行统计+1
						iCommentLines++;
					bCommentBeg=false;
					isNewLine=false;
					i++;
				}				
				else; 
				i++;
				continue;
			}
			if(c == ' '){
				i++;
				continue;
			} else if ((c == '\r' && line.charAt(i + 1) == '\n') || c == '\n') {
				if(!isNewLine)
					;
				else // 找到一个空行					
					iNullLines++;
				return;
			} else if (c == '/') {
				char c2 = line.charAt(++i);
				if (c2 == '/') {
					if(!isNewLine)
						;
					else // 这是个注释行
						// 注释行统计+1
						iCommentLines++;
					return;
				} else if (c2 == '*') {
					// 设置块注释开始标志
					bCommentBeg=true;					
				}
				else if(!bCommentBeg){
					if(!isNewLine)
						;
					else iValidLines++;
					return;
				}
			}			
			else {
				if(!isNewLine)
					;
				else iValidLines++;
				return;
			}
			i++;
		}
		if(!isNewLine) return;
		if(bCommentBeg  )
			iCommentLines++;
		else // 找到一个空行					
			iNullLines++;
		return;

	}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值