#what to change so it'll work
1 messages · Page 1 of 1 (latest)
<@&987246399047479336> please have a look, thanks.
please
String letter should probably be char letter
but if thats not possible, just use letter.charAt(0)
so ... == letter.charAt(0)
First of all Strings are arrays of char so you can reference to them without using charAt, just do myStr[index]
Then as dioxin said you can't compare chars to string, you have to compare chars with chars
char f = 'a'
char s = 'a'
if(f == s)
// this will work
its print nothing
whats in the array btw ? words or letters ?
right , there a 2 approaches then , either count all the hits u need, or just replace the non matches and count the lenght
it prints nothing because you're printing nothing
i mean return
U call the function but you do nothing with the value that it returns
im tryuing to return how many times a apperd
Yes, we got it
U have your function, which returns an int, this int is equals to how many letters it finds in the words it gets in the array when it is called, but this value that the function returns needs to be stored somewhere and then you can print it
so what should i do
Functions can either return void or return something, when it returns void you will just call it, it will be executed and then it will automatically returns null. When it returns something, that something must be stored into a variable
public static int sum(int a, int b) {
return a+b;
}
public static void main(String[] args) {
int abSum = sum(3, 9);
}
When the function is called, it sums the numbers and they are stored in abSum variable
Detected code, here are some useful tools:
but i return sum where i stored how many times a appare
(those are example Tvrsier is showing )
you cant use a string as an array
not in java
in c, sure
in java, you have no access the to underlying array
gotta use charAt to access characters
Actually, Strings in java are not even related to arrays
well its backed by an array, and there's toCharArray()
although theres nothing forcing String to use an array
Except it's not backed by a char[]
My point is that, as a java fashion, String encapsulate whatever is inside, so don't assume everything and use it like a regular class
i didnt say it was. it used to be, until it was changed to byte[]
still an array
why are you nit picking
ArrayList also encapsulates everything inside. could say "ArrayList are not related to arrays" using that premise
You are nitpicking 
My point is that, as a java fashion, String encapsulate whatever is inside, so don't assume everything and use it like a regular class
yes, but that wasnt the point. the point was they wanted to interface with String as one would in C
i was just saying its not possible, although you could use charAt
A string is a Sequence of Char, so a CharSequence