私は配列を使うことができ、テキストファイルを読み込み、テキストファイルからの情報で配列を満たすためにCollectionクラスを使うことができないクラスの割り当てに取り組んでいます。ファイルArrayData.txtは以下の情報です。 ファイルは、この方法でフォーマットされています2倍を含む配列で配列を塗りつぶす
3 //First line states how many sets are in the file
2 //Next line:there are x numbers in the set
10.22 567.98 //Next Line states the doubles that are in the set
//The pattern continues from there
1 // x numbers in the next set
20.55 // Double in the set
3
20.55 2.34 100.97
私の問題は、ダブルスで二番目の配列を埋め、アレイが初期配列を充填されます。
基本的に、私はそれは次のようになりたい:ここ
initArray[0]=> smallArray[2]={10.22,5.67.98}
initArray[1]=> smallArray[1]={20.55}
initArray[2]=> smallArray[3]={20.55,2.34,100.97}
は、私がこれまで持っているものです。
public static double[] largeArray;
public static double[] insideArray;
public static void main(String[] args) {
String fileInputName = "ArrayData.txt";
Scanner sc = null;
try {
sc = new Scanner(new BufferedReader(new FileReader(fileInputName)));
while (sc.hasNextLine()) {
int i = sc.nextInt();
largeArray= new double[i];
for(int x=0; x<i;x++)
{
int z = sc.nextInt();
insideArray= new double[z];
for(int y=0; y<z; y++)
{
insideArray[z]=sc.nextDouble();
}
}
}
}
catch (FileNotFoundException e) {
e.printStackTrace();
}
finally {
if (sc != null)
sc.close();
}
}
まず第一に、このロジックにも理にかなっていますか?第二に、私は範囲外の配列を取得し続けているので、私は何かが正しいことを知っている、私はちょうどどこか分からない。
これは間違った質問かもしれませんが、largeArrayの適切な場所にinsideArrayをどのように割り当てるのですか?それはlargeArray [i] [insideArray] –
'largeArray [x] = insideArray'のようになりますか?あるいは、 'largeArray [x]'で直接操作し、 'insideArray'をまったく使用しないかもしれません。 –
ありがとうございます!この固定されたすべて! –