引数 String moziretuに"test"と入力、戻り値char[] resultに返し、
public class WorkTest { public static void main(String[] args) { Work test = new Work(); System.out.println(test.divideIntoChars("test")); } }
次のプログラムで実行した場合に、
['t', 'e', 's', 't']
と表示をしたいのですが
test
と表示されます。
char[] result = moziretu.toCharArray();
を使って、この表示をしたかったのですがこれはできないのでしょうか?
もしくは
result[i] = result[i];
を変えれば表示できるのでしょうか?
どう変えればいいのか教えてください。
public class Work { /** @param moziretu 分解される文字列 * @return 分解された文字列 * @throws IllegalArgumentException */ public char[] divideIntoChars(String moziretu) throws IllegalArgumentException { if (moziretu == null) { throw new IllegalArgumentException(); } char[] result = moziretu.toCharArray(); for(int i=0;i<result.length;i++) { result[i] = result[i]; } return result; } }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/07/27 01:37