Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package stateBefore_After;
- public class Sentence implements Comparable<Sentence> {
- private String[] arr;
- private int max_length;
- private int index;
- public Sentence(String sentence) {
- this.arr = sentence.split("\\s+");
- this.max_length = arr[0].length();
- for(int i = 0; i < arr.length; i++) {
- if (max_length < arr[i].length()) {
- this.max_length = arr[i].length();
- this.index = i;
- }
- }
- }
- public String[] getArr() {
- return arr;
- }
- public int getMax_length() {
- return max_length;
- }
- public int compareTo(Sentence sentence) {
- if (max_length == sentence.getMax_length())
- return 0;
- else if (max_length < sentence.getMax_length())
- return -1;
- else if (max_length > sentence.getMax_length())
- return 1;
- else
- return max_length;
- }
- public String toString() {
- StringBuilder builder = new StringBuilder();
- for (int i = 0; i < arr.length; i++) {
- builder.append(arr[i] + " ");
- }
- return builder.toString();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment