Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Main {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- String word = scan.nextLine();
- char space = ' ';
- int countSpace = 0;
- for (int i = 1; i < word.length(); i++) {
- if (word.charAt(i) == space && word.charAt(i - 1) != space) {
- countSpace++;
- }
- }
- if (word.charAt(word.length() - 1) == space) {
- countSpace--;
- }
- String[] arrayWords = new String[countSpace + 1];
- for (int i = 0; i < arrayWords.length; i++) {
- arrayWords[i] = "";
- }
- int index = 0;
- for (int i = 0; i < word.length(); i++) {
- char symbol = word.charAt(i);
- if (symbol != space) {
- arrayWords[index] += symbol;
- continue;
- }
- if (i != 0 && word.charAt(i - 1) != space && i != (word.length() - 1)) {
- index++;
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment