我有一个实验室,我必须为我的计算机类做我有一个错误,我似乎无法弄清楚。我收到第一个if
声明的错误,if(something.indexOf(x) = "a")
。我想将其他if
声明更改为该形式。阵列发生意外的类型错误
我得到的错误是:
意想不到的类型 要求:变量:发现;值
Scanner in = new Scanner(System.in);
String[] input = new String[1000];
String[] output = new String[1000];
int x = 0;// All purpose counter
int y = 0;//Second purpose counter
boolean ends = false;
boolean starts = false;
/**
* This method is supposed to take the dna array and create an rna array from it to return
* to the main method wherever this method is called.
*
* @param String[] input The array that contains the dna sequence
* @return String[] output The array that contains the mRNA we just created in this method
*/
public void makeRNA()
{
System.out.println("Enter a simple DNA Sequence, make sure the amount of variables are a multiple of 3.");
String something = in.nextLine();
while(x < 1000)
{
if(something.indexOf(x) = "a")
{
output[x] = "u";
}
else if(input[x] == "c")
{
output[x] = "g";
}
else if(input[x] == "g")
{
output[x] = "c";
}
else if(input[x] == "t")
{
output[x] = "a";
}
x++;
}
for(x = 0 ; x < 1000; x++)
{
System.out.println(output[x]);
}
}
然后我得到的错误不兼容的类型:INT和Java。 lang.String –
这是因为'indexOf()'返回一个int并且“a”是一个字符串 – Ramanlfc
我猜你打算使用'.charAt()'? –