• ¡Welcome to Square Theme!
  • This news are in header template.
  • Please ignore this message.
مهمان عزیز خوش‌آمدید. ورود عضــویت


امتیاز موضوع:
  • 2 رای - 3 میانگین
  • 1
  • 2
  • 3
  • 4
  • 5
Title: source code Program for counting no. of Chars, Words and Lines in a file.
حالت موضوعی
#1
Program for counting no. of Chars, Words and Lines in a file.

سورس کد پیدا کردن تعداد کلمه ها و تعداد خط ها در یک فایل متنی

Source code
سورس کد :

کد:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication23;
import java.lang.*;
import java.io.*;
import java.util.*;
/**
*
* @author www.parsicoders.com
*/
public class JavaApplication23 {

   /**
    * @param args the command line arguments
    */


       public static void main(String arg[]) throws Exception
       {
               int char_count=0;
               int word_count=0;
               int line_count=0;
               String s;
               StringTokenizer st;
               BufferedReader buf=new BufferedReader(new InputStreamReader(System.in));
               System.out.print("Enter filename : ");
               s=buf.readLine();
               buf=new BufferedReader(new FileReader(s));
               while((s=buf.readLine())!=null)
               {
                       line_count++;
                       st=new StringTokenizer(s," ,;:.");
                       while(st.hasMoreTokens())
                       {
                               word_count++;
                               s=st.nextToken();
                               char_count+=s.length();
                       }
               }
               System.out.println("Character Count : "+char_count);
               System.out.println("Word Count : "+word_count);
               System.out.println("Line Count : "+line_count);
               buf.close();
       }
}

            
   


Example : & Output :
کد:
run:
Enter filename : e:\33.txt
Character Count : 23
Word Count : 4
Line Count : 4
BUILD SUCCESSFUL (total time: 9 seconds)
گروه دور همی پارسی کدرز
https://t.me/joinchat/GxVRww3ykLynHFsdCvb7eg
 
پاسخ
  


پرش به انجمن:


Browsing: 1 مهمان