I'm writing an inventory list program, that provides the user with option of adding an item to the list of exiting the program. To add an item the user enters 1 and is promoted to enter the item details( item name, price and quantity of the items). The information enter by the user is entered into a 3x3 2D array table, which already has a few values in it. The problem here is that I am finding it difficult to update/add new elements to the 3x3 2D array table. I've searched the internet for solutions, but I couldn't find any. Below is a code snippet of the 3x3 2D array table I wrote.
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// put your code here
int[][] one_d_array = {{2, 4, 6, 8}, {3, 5, 7, 9}};
int newArr[][] = new int[one_d_array.length + 1][one_d_array.length + 1];
Scanner sc = new Scanner(System.in);
System.out.println("Enter your desired number:");
int num = sc.nextInt();
System.out.println("Enter your desired number:");
int num2 = sc.nextInt();
//System.out.println(Arrays.toString(oned_array));
for (int i = 0; i < one_d_array.length; i++) {
for (int j = 0; j < one_d_array.length; j++) {
newArr[i][j] = one_d_array[i][j];
}
}
newArr[one_d_array.length][one_d_array.length] = ;
System.out.println(Arrays.toString(newArr));
}
}
P.S I'm new to arrays and don't really know how to use them.