#Why is my index not indexing?

1 messages · Page 1 of 1 (latest)

final lantern
#

So far I've written this code for this purpose...

"Complete the following program to find the first vowel in a word."


import java.util.Scanner;

public class FirstVowel
{
   public static void main(String[] args)
   {
      Scanner in = new Scanner(System.in);
      String word = in.next();

      boolean found = false;
      int i = 0;
      String ch = word.substring(i, i + 1);
      int position = 0;
      for (i = 0; i < word.length(); i++) {
         while (!found && position < word.length())
         {
            if ("aeiou".contains(ch.toLowerCase()))
            {
               found = true;
            }
            
            else
            {
            position++;
            }
            }
      }
      if (found)      
      {
         System.out.println("First vowel: " + ch);
         System.out.println("Position: " + position);
      }
      else
      {
         System.out.println("No vowels");
      }
   }
}```

However, my output is weird.

```Output differs. See highlights below.
Input
Mississippi
Your output
No vowels
Expected output
First vowel: i
Position: 1
2: Compare output
Input
able
Your output
First vowel: a
Position: 0
3: Compare output
Input
grrr!
Your output
No vowels

I think the issue is that it's not looking through all the characters in the string beyond the first, but I'm not sure how I could go about fixing that indexing issue in a while loop. Does anyone know how?

boreal lightBOT
#

<@&987246399047479336> please have a look, thanks.

boreal lightBOT
#

While you are waiting for getting help, here are some tips to improve your experience:

Code is much easier to read if posted with syntax highlighting and proper formatting.

If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.

Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.

#

Here is an AI assisted attempt to answer your question 🤖. Maybe it helps! In any case, a human is on the way 👍. To continue talking to the AI, you can use </chatgpt:1108714622413963314>.

#

There seems to be some missing code in your question. Could you please provide the complete code so that I can help you with the issue?

final lantern
#

Would anyone know?

glad cape
final lantern
#

Oy.

glad cape
#

which variable contains ur vowel?

final lantern
#

Hola.

glad cape
#

ch

#

print ch in ur loop

#

u will see it always says M

final lantern
#

Yeah.

#

I got it actually.

glad cape
final lantern
#

Ugh.

#

I'm sorry if I'm being really dumb about this btw.

glad cape
#

ur not. dont worry. its all about practice

final lantern
#

Yeah.

#

Honestly.

#

Are there any games IN Java?

glad cape
#

like minecraft or what do u mean?

final lantern
#

Yes.

#

Video games or game engines in Java.

glad cape
#

there are a few smaller things. mostly indie stuff

#

has nothing to do with java itself, more that the really big game engines just happen to not support it. and u would be insane to start a real game without a big game engine

#

nothing can compete with cryengine, unreal and unity

#

they are by far too feature-rich

#

there is LWJGL for java. but as said, dont expect anything that could compare to these big game engines

#

but if u want to make a java game, thats what u should use

final lantern
#

I see.

#

TBH I want to learn more about Java.

#

Because early in the year I was pretty ahead of the curve in my class.

#

Because I just got off a Python course and knew a lot of things.

#

BUT some mental health issues happened.

#

My grades took a shit and fell behind.

#

So now I'm trying to figure out wtf to do and all.

#

Like, how to deal with this Java class and all.

glad cape
#

:/

#

yeah. as u figured, its just a matter of practice and putting time into it

final lantern
#

Yeeup.