このメソッドは、文字列を取り込んで文字列として出力することになっていますが、サイズは 2 倍にする必要があります。例: 文字列は「PaRty」です。戻り値は「P」、「P」、「a」、「a」、「R」、「R」、「t」、「t」、「Y」、「Y」である必要があります
私のコードでは、テストを実行すると、要素 [];expected: で配列が異なると表示されますが、:
私は間違っていることを理解できず、誰かが私が理解してこれを機能させるために何かを指摘するのを手伝ってくれることを望んでいましたか? そして、私が1つずれている場合は、説明してください?
//Implementing the second method: toExpandedArray, which works with
//a string and then returns chars of that string.
public static char[] toExpandedArray(String string)
{
//Initializing variable needed to char the string
char[] charArray = new char[string.length() * 2];
//The loop that will turn the string into characters.
for (int i = 0; i < string.length(); i++)
{
charArray[i] = string.charAt(i) ;
charArray[i+1] = charArray[i];
i++;
}
//Returning the characters as an array.
return charArray;