13.
WAJP
that displays the number of characters, lines and words in a text/text file.
Program:
import java.io.*;
public class FileStat
{
public static void main(String args[])throws IOException
{
long n1=0,nw=0,nc=0;
String line;
BufferedReader br=new BufferedReader(new FileReader(args[0]));
while((line=br.readLine())!=null)
{
nl++;
nc=nc+line.length();
int i=0;
boolean pspace=true;
while(i<line.length())
{
char c=line.charAt(i++);
boolean cspace=Character.isWhitespace(c);
if(pspace&&!cspace)
nw++;
pspace=cspace;
}
}
public class FileStat
{
public static void main(String args[])throws IOException
{
long n1=0,nw=0,nc=0;
String line;
BufferedReader br=new BufferedReader(new FileReader(args[0]));
while((line=br.readLine())!=null)
{
nl++;
nc=nc+line.length();
int i=0;
boolean pspace=true;
while(i<line.length())
{
char c=line.charAt(i++);
boolean cspace=Character.isWhitespace(c);
if(pspace&&!cspace)
nw++;
pspace=cspace;
}
}
0 comments:
Post a Comment