Any ideas what could be the reason of this bug? I have added the spaces at the end of Strings.
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 BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
public static void main(String[] args) throws Exception {
String str = reader.readLine();
char[] temp = str.toCharArray();
String vowels = "";
String notVowels = "";
for(int i = 0;i<temp.length;i++)
{
if(isVowel(temp[i])){
vowels += String.valueOf(temp[i])+" ";
}
else if(temp[i]==(' ')){
}
else
{
notVowels += String.valueOf(temp[i])+" ";
}
}
System.out.println(vowels);
System.out.println(notVowels);
}
// 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;
}
}