-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathText.java
More file actions
26 lines (24 loc) · 912 Bytes
/
Text.java
File metadata and controls
26 lines (24 loc) · 912 Bytes
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
import java.util.*;
public class Text {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
System.out.println("\n\n\t\t\tText Statistics");
System.out.println("\t\t\t----------------");
System.out.println("Enter the text (type 'stop' on a new line to finish):");
int ch = 0, wc = 0, lc = 0;
while (true)
{
String st = s.nextLine();
if (st.equalsIgnoreCase("stop"))
break;
lc++;
String words[] = st.trim().split("\\s+");
if(!st.trim().isEmpty())
wc+=words.length;
ch += st.replace(" ", "").length();
}
System.out.println("\n\nNumber of Lines: " + lc);
System.out.println("Number of Words: " + wc);
System.out.println("Number of Characters (excluding spaces): " + ch);
}
}