2次元配列を持つクラスを作成しました。このクラスは、ユーザー入力とサイズに基づいて配列の数値を出力します。たとえば、ユーザー入力は 2 3 145464 のようになります。これは、配列のサイズが 2 行 3 列であり、配列内の数値を次のように出力する必要があることを意味します。
145
464
最初にサイズを宣言せずに配列のサイズを変更する方法がわかりません。
これは私が書いたものです
import java.util.Scanner;
public class Assignment7
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
int [][] nums = new int[scan.nextInt()][scan.nextInt()];
System.out.print("Enter numbers of an array ");
for (int i = 0; i < nums.length; ++i)
{
for (int j = 0; j < nums.length; ++j)
{
nums[i][j] = scan.nextInt();
}
}
for (int i = 0; i < nums.length; ++i)
{
System.out.print("\n");
for (int j = 0; j < nums.length; ++j)
{
System.out.print(nums[i][j]);
}
}
}
}