Could you please help me to understand the issue with my code? While running, it, it should print out only 2 lines, but for me it is printing out more lines.
Thank you for your help!
package com.codegym.task.task09.task0923;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
/*
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 {
// write your code here
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
char[] input = reader.readLine().toCharArray();
ArrayList<String> vowels = new ArrayList<>();
ArrayList<String> others = new ArrayList<>();
for (int i = 0; i < input.length; i++) {
if(isVowel(input[i])) {
vowels.add(String.valueOf(input[i]));
}
else {
others.add(String.valueOf(input[i]));
}
for (int j = 0; j < vowels.size(); j++) {
System.out.print(vowels.get(j) + " ");
}
System.out.println(" ");
for (int j = 0; j < others.size(); j++) {
System.out.print(others.get(j) + " ");
}
}
}
// 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;
}
}