I'm trying to create a program that allows the user to select between inputting the rows and columns of an array, inputting the values inside the array, and outputting the array. It all works fine until I try outputting the array, it always outputs 0's. How do I print the values properly?
public static void main(String[] args) { Scanner sc = new Scanner(System.in); char ans='y'; int column=0, row=0; do{ char c = menu(sc); int array[][] = new int [row] [column]; switch (Character.toLowerCase(c)) { case 'a': System.out.print("Enter row size "); row=sc.nextInt(); System.out.print("Enter column size "); column=sc.nextInt(); System.out.print("Row and Column "+row+" "+column); break; case 'b': for(int r=0;r<row;r++) { for(int col=0;col<column;col++) { System.out.print("Enter value for row "+r+" column "+col+": "); array[r][col]=sc.nextInt(); } } break; case 'c': for(int r=0; r<array.length; r++) { for(int col=0; col<array[r].length; col++) { System.out.print(array[r][col] + " "); } System.out.println(); } break; } System.out.println(""); }while(ans=='y'); }
menu(sc)doing?