Must be an array type but resolved to string

前端 未结 7 964
梦谈多话
梦谈多话 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:32

    You using String incorrectly. Instead of accessing via [] use dna.charAt(i).

    Altough logically a string is an array of characters in Java a String type is a class (which means it has attributes and methods) and not a typical array.

    And if you want to compare a single character to another enclose it with '' instead of "":

    if (dna.charAt(i) == 'c')
    .
    .
    

提交回复
热议问题