Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
program to count number of lines
//Title of this code //'main' method must be in a class 'Rextester'. import java.io.*; import java.util.Scanner; class Rextester { public static void main(String args[])throws IOException { String fname; Scanner obj=new Scanner(System.in); System.out.println("Enter any file name:"); fname=obj.nextLine(); File f1 = new File(fname); int s,nl=0,nc=0,nw=0; if(f1.exists()) { FileReader fs=new FileReader(f1); BufferedReader br=new BufferedReader(fs); while((s=br.read())!=-1) { if(s=='\n') nl++; else if(s==' ') nw++; else nc++; } System.out.println("Number of lines is:"+nl); System.out.println("Number of words is:"+nw); System.out.println("Number of charcter is:"+nc); } else { System.out.println("File does not exist"); } } }
run
|
edit
|
history
|
help
0
Remove punctuation except numbers, commas and spaces
PE #5
checkingWord
Abhay
java polymorhism
exp.1A
Java messing around
Compiler
2darray
Info by dfs