Solved

Points for laax

Posted on 2002-07-05
2
205 Views
Last Modified: 2010-03-31
Your idea in the tokienizer is sound but i can't seem to work anything out correctly.

Nevertheless, I'd like to thank you for your idea...

B)
0
Comment
Question by:DWolve
2 Comments
 
LVL 1

Accepted Solution

by:
laax earned 100 total points
Comment Utility
Hi DWolve,
   Thank you .... :-)
Laax.
0
 

Author Comment

by:DWolve
Comment Utility
public class LineOfCode{
     static int complexCommentFlag;

   public static void main (String [] args) {

String filename=null;

//     Add args=new String[]{"xxx"}; here

     int lineCount = 0;
     int blankSpace = 0;
     int simpleComment = 0;
     int complexComment = 0;
     complexCommentFlag = 0;

try
{
if(args.length==0)
{
     System.out.println("File Required");
}
else if(args.length==1)
{
     filename=args[0];
BufferedReader in = new BufferedReader(new FileReader(filename));
     String line = null;
     
     while (null!=(line=in.readLine()))
     {
          line = line.trim();
          if (line.length()>=0)
          {
               if (line.length()==0)
               {
                    blankSpace++;
               }
               
               if(line.startsWith("//"))
               {
                    simpleComment++;
               }              

               if(line.startsWith("/*"))
               {
                    complexCommentFlag=1;
               }
               if (complexCommentFlag==1)
               {
                    complexComment++;
               }
               if(line.endsWith("*/"))
               {
                    complexCommentFlag=0;
               }

               lineCount++;
          }
     }

     System.out.println("Number of Line = " + lineCount);
     System.out.println("Number of Blank Lines= " + blankSpace);
     System.out.println("Number of Coded Lines= " +lineCount +" - " +blankSpace+" = "+ (lineCount - blankSpace));
     System.out.println("Number of Lines that starts with // = " + simpleComment);
     System.out.println("Number of Lines that within /*--*/ border = " + complexComment);
     System.out.println("Number of Lines of Comment = "+simpleComment+" + "+complexComment+" = "+(complexComment+simpleComment)+"\n");

     System.out.println("Executing File test on "+filename);
     System.out.println("---------------------------------------------------------------");
     System.out.println("Number of Lines in File = " + lineCount);
     System.out.println("Number of Lines of Comment = "+(complexComment+simpleComment));
     System.out.println("Number of Executable Lines = "+(lineCount-complexComment-simpleComment-blankSpace));

}
}
catch (java.io.FileNotFoundException e)
{
     System.out.println("File not found.");
     return;
}
catch (java.io.IOException ioe){
}
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now