Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Arrays;
- public class Season7Task2 {
- public static void main(String[] args) {
- String str = "I should have studied more. The teacher told me that I have to study more. "
- + "I curse myself for not studying more. "
- + "The more I study, the better I get. "
- + "But I did not study more, so I am not better now.";
- String[] arr = str.split("\\.");
- int sentenceNumber = arr.length;
- int longestSentence = arr[0].length();
- int longestSentenceIdx = 0;
- for (int i = 1; i < arr.length; i++) {
- if(arr[i].length() > longestSentence){
- longestSentence = arr[i].length();
- longestSentenceIdx = i;
- }
- }
- String[]longestWords = new String[arr.length];
- int longestWordsIdx = 0;
- System.out.println("Longest words:"+Arrays.toString(longestWords)+".");
- System.out.println("Longest sentence:" + arr[longestSentenceIdx].trim()+".");
- System.out.println("Total sentences:" + sentenceNumber);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment