-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWcLib.java
More file actions
29 lines (23 loc) · 710 Bytes
/
Copy pathWcLib.java
File metadata and controls
29 lines (23 loc) · 710 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
27
28
29
import java.lang.*;
class WcLib{
private String givenData;
public WcLib(String givenString){
this.givenData = givenString;
}
public int getCharacterCount(){
return this.givenData.length();
}
public int getWordCount(){
return (this.givenData.length() == 0) ? 0 : this.givenData.split("\\s+").length;
}
public int getLineCount(){
return (this.givenData.length() == 0) ? 0: this.givenData.split("\n").length;
}
public int getByteCount(){
return this.givenData.getBytes().length;
}
public int[] getLinesWordsBytes(){
int[] result = {this.getLineCount(),this.getWordCount(),this.getByteCount()};
return result;
}
}