Must be an array type but resolved to string

前端 未结 7 957
梦谈多话
梦谈多话 2021-01-16 07:01

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\'

相关标签:
7条回答
  • 2021-01-16 07:51

    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 ints to double:

    double answer = count/(double)dna.length();
    
    0 讨论(0)
提交回复
热议问题