我最近在這裏問了一個問題,並學習瞭如何拆分我的陣列。現在我正忙於存儲分離的數組。我知道這個代碼可能是非常錯誤的,因爲我只是想弄明白自己。此代碼的預期目的是查看在分割數組(可以是10個名稱和10個角度)之後是否可以存儲輸入。 System.out的目的是查看它們是否存儲。我不斷收到符號結果找不到的錯誤。任何幫助表示讚賞。分割和存儲數組的正確方法?
import java.util.ArrayList;
import java.util.Arrays;
import javax.swing.JOptionPane;
public class PeerTutoring
{
public static void main(String[] args)
{
ArrayList<String> list = new ArrayList<String>();
int a = 0;
int b = 1;
int c = 0;
int d = 1;
for(int i=0;i<20;i++) {
String line;
line = JOptionPane.showInputDialog("Please enter tutor name and their highest earned degree.");
String[] result = line.split("\\s+");
String[] name = new result[a];
String[] degree = new result[b];
a++;
b++;
System.out.println(name[c]);
System.out.println(degree[d]);
c++;
d++;
}
}
'String [] result = line.split(「\\ s +」);'此行已經有您的String int0 String數組用空格分隔。 – Smit 2013-03-26 00:23:34