简体   繁体   English

基于用户的乘法表

[英]User based Multiplication Table

Hi I need help with my code. 嗨,我需要代码帮助。 Im trying to make a user base input multiplication table using a Scanner and a method, but i dont know how to get the user base input from the main method to the method i created, here is what i have so far: 我正在尝试使用扫描仪和方法制作用户基础输入乘法表,但是我不知道如何从主要方法到我创建的方法中获得用户基础输入,这是我到目前为止所拥有的:

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 ();
}

You can pass like : 您可以通过:

    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

Actually your codes are pretty closed. 实际上,您的代码非常封闭。 Please see below (I have tested the codes): 请参阅下面的内容(我已经测试了代码):

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);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM