有2個數組。 代碼[]和文本[]如何整理只包含字母的數組?
code[0] = 0, text[0] = "Monkey333banana" // has numbers in text
code[1] = 100, text[1] = "Dog"
code[2] = 200, text[2] = "Cat117" // has numbers in text
code[3] = 300, text[3] = "Pig"
我想拿起文本的數組[] 僅由字母。 沒有號碼。
code[1] = 100, text[1] = "Dog"
code[3] = 300, text[3] = "Pig"
而我想保存另一個新的數組。
newCode[0] = 100, text[0] = "Dog"
newCode[1] = 300, newText[1] = "Pig"
示例代碼:
String[] code = new String[4];
int[] text = new int[4];
code[0] = 0;
code[1] = 100;
code[2] = 200;
code[3] = 300;
text[0] = "Monkey333banana";
text[1] = "Dog";
text[2] = "Cat117";
text[3] = "Pig";
// *** MAGIC **** //
// *** MAGIC **** //
// *** MAGIC **** //
for (int i=0; i<(proper size); i++)
System.out.println(newCode[i]+" : "+newText[i]);
結果:
- 100:狗;
- 300:豬;
我該怎麼做這個魔法?請幫幫我。謝謝!
對不起......對行爲輕率,我寫了magic
也許有人認爲這是不好的,對不起......
使用循環來分隔它們。你應該使用'class'來分組文本和代碼。 –
您介紹'code'數組,但我沒有看到您在任何地方使用它。你的意思是輸出應該是「100:狗,300:豬」? – kba
@kba對不起!我的錯。我編輯。謝謝! – Juntae