Guest User

Untitled

a guest
Jan 7th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. import java.util.Arrays;
  2. public class Season7Task2 {
  3.  
  4. public static void main(String[] args) {
  5.  
  6. String str = "I should have studied more. The teacher told me that I have to study more. "
  7. + "I curse myself for not studying more. "
  8. + "The more I study, the better I get. "
  9. + "But I did not study more, so I am not better now.";
  10.  
  11. String[] arr = str.split("\\.");
  12. int sentenceNumber = arr.length;
  13. int longestSentence = arr[0].length();
  14. int longestSentenceIdx = 0;
  15.  
  16. for (int i = 1; i < arr.length; i++) {
  17. if(arr[i].length() > longestSentence){
  18. longestSentence = arr[i].length();
  19. longestSentenceIdx = i;
  20. }
  21. }
  22. String[]longestWords = new String[arr.length];
  23. int longestWordsIdx = 0;
  24.  
  25.  
  26.  
  27. System.out.println("Longest words:"+Arrays.toString(longestWords)+".");
  28. System.out.println("Longest sentence:" + arr[longestSentenceIdx].trim()+".");
  29. System.out.println("Total sentences:" + sentenceNumber);
  30.  
  31. }
  32.  
  33. }
Advertisement
Add Comment
Please, Sign In to add comment