基于用户的乘法 Table

User based Multiplication Table

您好,我的代码需要帮助。我正在尝试使用扫描仪和方法进行用户基础输入乘法 table,但我不知道如何将用户基础输入从主要方法获取到我创建的方法,这是我目前所拥有的:

public static void multiplicationTable(int i){
for (int i=1;i<=size;i++){
for (int j=1;j<=size;j++)
System.out.print("\t"+i*j);
System.out.println(); }
}
public static void main (String[] args) {
System.out.println("This program displays a multiplication table.");
Scanner size = new Scanner(System.in);
System.out.println("Enter a positive integer: ");
int n = size.nextInt ();
}

其实你的代码已经很封闭了。请看下面(我已经测试过代码):

public static void multiplicationTable(int size) {
    for (int i = 1; i <= size; i++) {
        for (int j = 1; j <= size; j++) {
            System.out.print("\t" + i * j);
        }
        System.out.println();
    }
}

public static void main(String[] args) throws Exception {
    System.out.println("This program displays a multiplication table.");
    Scanner size = new Scanner(System.in);
    System.out.println("Enter a positive integer: ");
    int n = size.nextInt();
    multiplicationTable(n);
}

你可以通过:

    System.out.println("This program displays a multiplication table.");
    Scanner size = new Scanner(System.in);
    System.out.println("Enter a positive integer: ");
    int n = size.nextInt ();
    multiplicationTable(n); \ pass here