I am getting the \"Must be an array type but it resolved to string\" error in my code. It also says that i (in the code below) cannot be resolved to a variable which I don\'
You cannot access a String's character using subscript (dna[i]
). Use charAt instead:
dna.charAt(i) == 'c'
Also, "c"
is a String
, 'c'
is a char
.
One more thing - integer division ( e.g. int_a / int_b
) results in an int, and so you lose accuracy, instead - cast one of the int
s to double
:
double answer = count/(double)dna.length();