I'm working on the vowel counting problem at coedabbey, but my solution doesn't seem to be working. Here's what I'm doing:
import java.util.Scanner;
public class Solution {
private static Scanner input;
public static void main(final String[] args){
input = new Scanner(System.in);
int amount = input.nextInt();
for(int i = 0 ; i < amount ; i++){
int sum = 0;
String nowa = input.nextLine();
for(int j = 0; j < nowa.length() ; j++){
char x = nowa.charAt(j);
if(x == 'a' || x == 'o' || x == 'u' || x == 'i' || x == 'e' || x == 'y'){
++sum;
}
}
System.out.println(sum+ " ");
}
}
}
But it does not do the right number of lines, and always outputs 0
for the count for a line after I enter the input. After that it does one fewer line than I expected.
An example run might look as follows:
> java Solution
> 3
0
> hello
2
> george
3
But, I wanted to enter another line because I said "3" at the beginning.
Skip a line after
nextInt()
as it doesnt consumes whole line it consumes only tokenDemo