配列について助けが必要です。私の質問は、100 個の要素を持つ整数配列を作成したことです。ユーザーが 100 より大きい値を入力すると、Java は例外をスローします。ユーザーが配列に 100 を超える値を入力できるようにすると、ArrayOutOfBoundsException がユーザーにスローされます。ここにコードがあります:
編集サブ配列を含む配列が正しいかどうかを尋ねるのを忘れていました。ちなみに、これはArrayListではなくプレーン配列で行いたいです。
public class Lab6
{
public static void main(String[] args)throws IOException, NullPointerException, ArrayIndexOutOfBoundsException
{
//the memory with 100 elements
int[] vMem = new int[100];
//the memory with 1000 elements
int[][] vTopMem = new int[1000][];
vTopMem[0] = vMem;
System.out.println("Enter an integer: ");
File vMemory = new File("file name and location");
RandomAccessFile storeMem = new RandomAccessFile(vMemory, "rw");
Scanner input = new Scanner(System.in);
while(true)
{
for(int i = 0; i < vMem.length; i++)
{
vMem[i] = input.nextInt();
storeMem.write(i);
if(i > vMem.length)
{
System.out.println("out of bounds!");
}
}
}
}
}