+ 4

Check for a character in a string[solved]

How to solve my error? I want to check if a character is present in a string. Plz help me plz plz🥺🥺 https://code.sololearn.com/cJxU68WfosOX/?ref=app

6th Oct 2021, 5:49 AM
Rishi
Rishi - avatar
6 ответов
+ 4
Martin Taylor wow, you put so much effort to do this. Like you write those big copywrite stuff and other information. Tnx for answer =) I noted all
6th Oct 2021, 10:42 AM
Rishi
Rishi - avatar
+ 3
1. You can get a character from a String with "string".charAt(index); 2. The .contains() method however needs another String so you can either think of a way to give it a String maybe with .substring(index, index + 1) or you can change your vowels to an int array[127] and use the vowel characters as indexes. int array[] vowels = new int[127]; vowels['a']++; vowels['e']++ vowels['i']++; etc... then in your for loop (which by the way is missing it's break condition so you need to add it maybe check the longest string's lenght) you can use if (vowels[s1.charAt(i)] > 0) { ++vowels_s1; }
6th Oct 2021, 8:06 AM
Kamen Studentov
Kamen Studentov - avatar
+ 3
I have only corrected your code Rishi . There you can see why you got the errors: https://code.sololearn.com/cZsbyCTagXBy/?ref=app
6th Oct 2021, 8:48 AM
JaScript
JaScript - avatar
+ 1
Rishi, What is it are you trying to do? find what in which variable?
6th Oct 2021, 9:15 AM
Ipang
+ 1
Ipang I'm trying to find the number of vowels in each string. I solved it, but tell me if you have any idea to solve this.
6th Oct 2021, 10:32 AM
Rishi
Rishi - avatar
+ 1
Thank you guys I got it to work =)
6th Oct 2021, 10:36 AM
Rishi
Rishi - avatar