Q:

n-by-n integer array

Problem statement:
I want to write a program that reads in a positive integer n from standard input and creates an n-by-n integer array a[][] such that a[i][j] is the product of (i+1)th row with the (j+1)th column.
Current Code:
Scanner input = new Scanner(System.in);
String inputString;
char flag = 'y';
while (flag != 'q' && flag != 'Q') {
    System.out.print("Enter a positive integer:");
    int value = input.nextInt();
    System.out.printf("Enter q to quit or any other key to quit: ");
    input.nextLine();
    inputString = input.nextLine();
    flag = inputString.charAt(0);
}

For example 
if the user enters 3 the matrix needs to be 3x3 and have the product of  1 multiplied by 1, 1 multiplied by 2 and 1 multiplied by 3. Then do the same thing for 2 and 3. 

A:

 public static void main(String[] args) {
    Scanner input = new Scanner(System.in);

    String inputString;
    char flag = 'y';
    int matrix[][];
    while (flag != 'q' && flag != 'Q') {
        System.out.print("Enter a positive integer:");
        int value = input.nextInt();
        System.out.printf("Enter q to quit or any other key to quit: ");
        if(value > 0){
            matrix = new int[value][value];
            displayOutput(matrix);
        }

        input.nextLine();
        inputString = input.nextLine();
        flag = inputString.charAt(0);
    }
}

private static void displayOutput(int[][] matrix) {
    for (int i = 0; i < matrix.length; i++) {

        matrix[i][0] = i+1;
    }
    for (int j = 1; j < matrix.length; j++) {
        for (int i = 0; i < matrix.length; i++) {
            matrix[i][j] = matrix[i][0]*(j+1);
        }            
    }

    for (int i = 0; i < matrix.length; i++) {
        for (int j = 0; j < matrix.length; j++) {
            System.out.print(" "+matrix[i][j]);
        }
        System.out.println("");
    }

}
Input: 3
Outputs: 1 2 3
         2 4 6
         3 6 9

