Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- class Main {
- public static void main (String[] args) {
- Scanner scan = new Scanner(System.in);
- String str = scan.nextLine();
- String firstFour = "";
- int wordCount = 1;
- int sentenceNum = 1;
- int i = 0;
- int st = 0;
- while (i < str.length()) {
- char c = str.charAt(i);
- if (c == '.') {
- System.out.println(sentenceNum + ": " + firstFour + " || " + wordCount);
- wordCount = 0;
- sentenceNum++;
- st = i+2;
- } else if (c == ' ') {
- wordCount++;
- if (wordCount == 5) {
- firstFour = str.substring(st, i);
- }
- }
- i++;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement