Guys,
do you have any idea how I evade the extra space in the second line?
greetings, Fabian
package com.codegym.task.task09.task0923;
import java.io.BufferedReader;
import java.io.InputStreamReader;
/*
Vowels and consonants
*/
public class Solution {
public static char[] vowels = new char[]{'a', 'e', 'i', 'o', 'u'};
public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String source = reader.readLine();
char src[] = source.toCharArray();
for(char s : src) {
if(isVowel(s)) {
System.out.print(s +" ");
}
}
System.out.println("");
for(char s : src) {
if(!isVowel(s)) {
System.out.print(s);
System.out.print(" ");
}
}
}
// The method checks whether a letter is a vowel
public static boolean isVowel(char c) {
c = Character.toLowerCase(c); // Convert to lowercase
for (char d : vowels) // Look for vowels in the array
{
if (c == d)
return true;
}
return false;
}
}