Wind Blowing on a String

I have a basic idea on how to accomplish this task, but I'm not sure if I am doing it right. So, we have a WindyString class with a meteor strike. After use:

System.out.println(WindyString.blow(
    "Abrakadabra!          The    second  chance to pass has already BEGUN! "));

we should get something like this:

                    e              a  e         a           a  ea y
   br k d br !    Th    s c nd   ch nc    t    p ss   h s    lr  d    B G N!
  A  a a a  a            e o               o           a               E U

therefore, in a nutshell, in every second word, we select all the vowels and move them one line above. In the second half of the words, we move the vowels one line below.

I know that I have to split the string into tokens using the tokenizer or the split method, but what's next? Create 3 arrays, each of which represents each row?

+5
source share
2 answers

- . :

static String blow(String s) {
    String vowels = "aeiouAEIOU";
    String middle = s.replaceAll("[" + vowels + "]", " ");
    int flip = 0;
    String[] side = { "", "" };
    Scanner sc = new Scanner(s);
    for (String word; (word = sc.findInLine("\\s*\\S*")) != null; ) {
        side[flip] += word.replaceAll(".", " ");
        side[1-flip] += word.replaceAll("[^" + vowels + "]", " ");
        flip = 1-flip;
    }
    return String.format("|%s|%n|%s|%n|%s|", side[0], middle, side[1]);
}

| , , - , , .

, , , .

middle - , .

side[0] side[1] - . Scanner ( ). , , , ; , . , .

+2

, , , ( ) .

3 ; , 2 (Arrays.fill) ' '.

, , , , , .

, . , (/) . , boolean . , , : , . -, reset .

.

+5

All Articles