Advertisement
CaptainSpaceCat

Writing Analysis Chart V1

Sep 5th, 2016
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.70 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. class Main {
  4.  
  5.   public static void main (String[] args) {
  6.     Scanner scan = new Scanner(System.in);
  7.    
  8.     String str = scan.nextLine();
  9.    
  10.     String firstFour = "";
  11.     int wordCount = 1;
  12.     int sentenceNum = 1;
  13.     int i = 0;
  14.     int st = 0;
  15.     while (i < str.length()) {
  16.       char c = str.charAt(i);
  17.       if (c == '.') {
  18.         System.out.println(sentenceNum + ": " + firstFour + " || " + wordCount);
  19.         wordCount = 0;
  20.         sentenceNum++;
  21.         st = i+2;
  22.       } else if (c == ' ') {
  23.         wordCount++;
  24.         if (wordCount == 5) {
  25.           firstFour = str.substring(st, i);
  26.         }
  27.       }
  28.       i++;
  29.     }
  30.    
  31.   }
  32.  
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement