Gleb01

кусок кода

Jan 20th, 2020
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 1.00 KB | None | 0 0
  1. public class Main {
  2.     public static void main(String[] args) {
  3.         Scanner scan = new Scanner(System.in);
  4.         String word = scan.nextLine();
  5.         char space = ' ';
  6.         int countSpace = 0;
  7.         for (int i = 1; i < word.length(); i++) {
  8.             if (word.charAt(i) == space && word.charAt(i - 1) != space) {
  9.                 countSpace++;
  10.             }
  11.         }
  12.         if (word.charAt(word.length() - 1) == space) {
  13.             countSpace--;
  14.         }
  15.         String[] arrayWords = new String[countSpace + 1];
  16.         for (int i = 0; i < arrayWords.length; i++) {
  17.             arrayWords[i] = "";
  18.         }
  19.         int index = 0;
  20.         for (int i = 0; i < word.length(); i++) {
  21.             char symbol = word.charAt(i);
  22.             if (symbol != space) {
  23.                 arrayWords[index] += symbol;
  24.                 continue;
  25.             }
  26.             if (i != 0 && word.charAt(i - 1) != space && i != (word.length() - 1)) {
  27.                 index++;
  28.             }
  29.         }
  30.     }
  31. }
Add Comment
Please, Sign In to add comment