我有一個實驗室,我必須爲我的計算機類做我有一個錯誤,我似乎無法弄清楚。我收到第一個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()'? –