0

I am currently trying to make a simple program that will calculate the number of vowels in multiple sentences. The input looks like this:

6

Emily jumped high

Alex did not jump

Phillip hates jumping

The red dragon can fly

Sandwiches are nice

I like the sun

The number indicates how many lines there are. My problem is that when I print out the results, the last line gets ignored. So the program prints out 5 ints, rather than 6.For some reason when I posted the input, it would automatically show me the first 5 ints, I then just had to press enter to make the last one show up.

Scanner in = new Scanner(System.in);
int cases = in.nextInt(); //how many lines there are 
String a; 
int vowels = 0;
int length; //length of a line
char temp;
in.nextLine(); //skips first line of the input, as this declares how many lines there are

for (int i = 0; i < cases; i++) 
{
    a = in.nextLine();
    length = a.length();
    
    for (int b = 0; b < length; b++)
    {
        temp = a.charAt(b);
        if (temp == 'a' || temp == 'e' || temp == 'i' || temp == 'o' || temp == 'u')
        {
            vowels++;
        }
    }
    System.out.println(vowels);
    vowels=0;
}
Jens
  • 67,715
  • 15
  • 98
  • 113
Maniram
  • 1
  • 1
  • 3
    it works fine on my machine, prints out six ints – geco17 Nov 14 '21 at 08:36
  • Which console do you use? Is it an IDE-cconsole or a system/os-console? – n247s Nov 14 '21 at 10:19
  • I used Intelli-j IDE. – Maniram Nov 14 '21 at 12:27
  • You could try adding a `System.out.flush()` at the end, if that doesn't work it might be related this issue: https://stackoverflow.com/questions/39798849/intellij-idea-debug-run-console-system-out-flush-not-flushing. It is pretty straight old, but as far as I can see still unresolved. – n247s Nov 14 '21 at 16:00

0 Answers0