FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
java-basics/java-programs/CountCharactersInFile.java at master · learning-zone/java-basics · GitHub
learning-zone
/
java-basics
Public
Notifications
You must be signed in to change notification settings
Fork
875
Star
1.9k
Code
Issues
0
Pull requests
0
Discussions
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
java-basics
/
java-programs
/
CountCharactersInFile.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
45 lines (38 loc) · 1.33 KB
Breadcrumbs
java-basics
/
java-programs
/
CountCharactersInFile.java
Copy path
File metadata and controls
45 lines (38 loc) · 1.33 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package
misc
;
import
java
.
io
.
BufferedReader
;
import
java
.
io
.
File
;
import
java
.
io
.
FileInputStream
;
import
java
.
io
.
IOException
;
import
java
.
io
.
InputStreamReader
;
public
class
CountCharactersInFile
{
public
static
void
main
(
String
[]
args
)
throws
IOException
{
File
file
=
new
File
(
"file.txt"
);
FileInputStream
fis
=
new
FileInputStream
(
file
);
InputStreamReader
input
=
new
InputStreamReader
(
fis
);
BufferedReader
reader
=
new
BufferedReader
(
input
);
String
line
;
int
countWord
=
0
;
int
sentenceCount
=
0
;
int
characterCount
=
0
;
int
paragraphCount
=
1
;
int
whitespaceCount
=
0
;
while
((
line
=
reader
.
readLine
()) !=
null
) {
if
(
line
.
equals
(
""
)) {
paragraphCount
++;
}
if
(!(
line
.
equals
(
""
))) {
characterCount
+=
line
.
length
();
String
[]
wordList
=
line
.
split
(
"
\\
s+"
);
countWord
+=
wordList
.
length
;
whitespaceCount
+=
countWord
-
1
;
String
[]
sentenceList
=
line
.
split
(
"[!?.:]+"
);
sentenceCount
+=
sentenceList
.
length
;
}
}
System
.
out
.
println
(
"Total word count = "
+
countWord
);
System
.
out
.
println
(
"Total number of sentences = "
+
sentenceCount
);
System
.
out
.
println
(
"Total number of characters = "
+
characterCount
);
System
.
out
.
println
(
"Number of paragraphs = "
+
paragraphCount
);
System
.
out
.
println
(
"Total number of whitespaces = "
+
whitespaceCount
);
}
}
Back
|
FazBrowse Home
|
New Git URL