so I have a task for an online course (in which the forums are no longer active) where i have to find the ratio of letters (C and G) in a string.
I've marked where i'm getting an out of bounds error -1 with ***
although i'm stuck as to why
pls help
p.s. the error is all i need help with at the moment, I would prefer to figure the rest out on my own :)
public String cgRatio (String dna){
int currIndex = 0;
float cCount = 0;
float gCount = 0;
int startIndex = 0;
while (true){
currIndex = dna.indexOf(startIndex);
if ( dna.substring(currIndex, currIndex +1) == "C"){ ***
cCount ++;
}
if (dna.substring(currIndex, currIndex +1) == "G"){
gCount ++;
}
if (currIndex >= dna.length()){
break;
}
startIndex = currIndex +1;
}
return "c to g ratio is " + (cCount/gCount);
}
//being called to:
public void test(){
cgRatio ("CCATGCCCCTATAGTAGATGTTAAAAGAAATATGAACTTAGATTAAGA AACCCC"); ***
cgRatio ("");
cgRatio ("ATGTATAGATATAAATATAGAGSsaegTGATAGoiajhegoijaTGA" );
}