Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: How to count the lines of code in a class and a method?

  1. #1
    Junior Member
    Join Date
    Sep 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How to count the lines of code in a class and a method?

    By far, I have written the code to find the lines of code in a program. I want to extend it to find the lines of code in a class and method...


     
    import java.io.BufferedReader;
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.io.FileReader;
    import java.io.LineNumberReader;
    import java.util.Scanner;
     
     
    public class LinesOfCode {
     
        public static void main(String[] args) 
        {
            try
            {
             BufferedReader reader= new BufferedReader(new FileReader
             ("C:\\Users\\Kalyani\\Documents\\NetBeansProjects\\HelloWorld\\src\\MeanStandardDeviation.java"));
     
             int totalLines=0;
             int emptyLines=0;
             String line="";
     
            while((line=reader.readLine())!= null)
            {
                line=line.trim();
     
                if(line.isEmpty())
                {
                    emptyLines++;
                    continue;
                }
     
                totalLines++;
            }
     
     
            System.out.print("Total Lines : "+totalLines+" LOC\n");
            System.out.print("Empty Lines : "+emptyLines+" LOC\n");
     
     
            }
     
            catch(FileNotFoundException e)
            {
              System.out.print(e.getMessage());
            }
     
            catch(Exception e)
            {
              System.out.print(e.getMessage());
            }
     
        }
    }
    Last edited by kalyanisingh; October 4th, 2014 at 09:45 AM.


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: How to count the lines of code in a class and a method?

    Welcome to the forum! Please read this topic to learn how to post code in code or highlight tags and other useful info for new members.

    Please post your code correctly using code or highlight tags per the above link.

  3. #3
    Junior Member
    Join Date
    Sep 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Arrow Re: How to count the lines of code in a class and a method?

    Okay....done....

  4. #4
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: How to count the lines of code in a class and a method?

    And what help do you need to realize what you want?

  5. #5
    Junior Member
    Join Date
    Sep 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How to count the lines of code in a class and a method?

    Quote Originally Posted by GregBrannon View Post
    And what help do you need to realize what you want?


    In the code above,I want to add the functionality of counting lines of class and methods separately....

  6. #6

    Default Re: How to count the lines of code in a class and a method?

    thank you for sharing this code, it really works well. very easy to understand .

Similar Threads

  1. Replies: 10
    Last Post: July 1st, 2014, 02:41 PM
  2. [SOLVED] Trying to rewrite the main method to use as few lines of code as possible
    By jc100 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: September 26th, 2013, 08:28 PM
  3. Recursive Method to count vowel
    By hofamilyiiii in forum What's Wrong With My Code?
    Replies: 6
    Last Post: June 18th, 2013, 08:43 AM
  4. Method to count objects
    By mjpam in forum Java Theory & Questions
    Replies: 5
    Last Post: July 28th, 2010, 08:49 AM
  5. How can i add a new count to this source code ?
    By mm2236 in forum File I/O & Other I/O Streams
    Replies: 0
    Last Post: January 30th, 2010, 10:21 PM

Tags for this Thread