こんにちはみんな...文字列配列に10個のランダムな文字列を得るには?文字列が取られている私は、Javaの配列に(96文字程度)文字列の集合からランダムに10の文字列を取る方法を作成する方法を知りたい
は、テキストファイル を形成し、これは、ファイルを読み取り、質問配列
Qを作成するための私のコードです
も私はすでにファイルを読み込み、ライン に変数を割り当てるための方法を作成し、私は質問の配列を作成した質問であるa ch o
b ....
。
。
CAが正解
public static Question[] readAllQuestions() throws FileNotFoundException {
int numberOfQuestions = CountQuestions();
Question [] allQuestions = new Question[numberOfQuestions];
Scanner file = new Scanner (new File("TestBank.txt"));
String q = "";
String aa = "";
String bb = "";
String cc = "";
String dd = "";
String ccA = "";
int x = 0 ;
int k = 0 ;
while (x< (allQuestions.length-1)) {
while (file.hasNext() && k == 0) {
String ques[] = file.nextLine().split(" ");
for (int ww = 0 ; ww< ques.length ; ww++) {
q += ques[ww];
q+=" ";
}
if(ques[0].equals("")) {
k++ ;
}
}
while (k == 1) {
String a[] = file.nextLine().split(" ");
for (int ww = 0; ww< a.length; ww++) {
aa += a[ww];
aa+= " ";
}
if(a[0].equals("")) {
k++ ;
}
}
//file.hasNext() &&
while (k == 2) {
String b[] = file.nextLine().split(" ");
for (int ww = 0 ; ww< b.length ; ww++) {
bb += b[ww];
bb+= " ";
}
if(b[0].equals("")) {
k++;
}
}
while (k == 3) {
String c[] = file.nextLine().split(" ");
for (int ww = 0; ww<c.length; ww++) {
cc += c[ww];
cc+= " ";
}
if(c[0].equals("")) {
k++;
}
}
while (k == 4) {
String d[] = file.nextLine().split(" ");
for (int ww = 0; ww< d.length; ww++) {
dd += d[ww];
dd+= " ";
}
if(d[0].equals("")) {
k++;
}
}
while (k == 5) {
String cA[] = file.nextLine().split(" ");
for (int ww = 0; ww<cA.length; ww++) {
ccA += cA[ww];
ccA += " ";
}
if(cA[0].equals("")) {
k++;
}
}
while (k == 6) {
Question question = new Question(q,aa,bb,cc,dd,ccA);
allQuestions[x] = question;
q="";
aa="";
bb="";
cc="";
dd="";
ccA="";
x++;
k=0;
}
}
return allQuestions;
}
任意のアイデアですか? ありがとう
私は配列を印刷すると、データだけではなくアドレスを出力します。 – Ammar
[質問@ 3d4eac69、質問@ 42a57993、.......] – Ammar
要素を印刷するためにループを使用します。 –