• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Lines of Code Counter in servlet

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I need to take a java file as an input to a servlet program and implement LOCcounter() function, to count th LOC of the program, ignoring blankslines and comments. Im not going anywhere, please hlp me
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Whether you do this in a Servlet or not is moot, so I've moved this to the Beginner java forum for any discussion.
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Avinash,
Welcome to the Ranch.

Since we do not hand out ready made code here at the Ranch, I will share some pseudo code with you.
1) Open a stream to the. For this you can either use BufferedReader or Scanner
2) Read one line at a time
3) Increment the counter
4) When you finish reading the file, the counter will tell you the number of lines.

This is basic stuff. You need to build logic for identifying if the read line is empty and if the read line was part of some comment.
You have also failed to take into consideration the package statement and import statements. If you ignore them, your code is going to be flawed.

What have you got so far and where are you stuck?
reply
    Bookmark Topic Watch Topic
  • New Topic