我该如何纠正这个Java程序?

时间:2015-02-20 06:48:07

标签: java

我在Java编程方面非常业余。请帮我纠正这个程序,因为它在if循环中有错误:

import java.util.Scanner;

public class MyMultiplyProgram {

    public static void main(String[] args) {
        System.out.println("Please enter your number: ");
        Scanner keyboardInput = new Scanner(System.in);
        int numberOne = keyboardInput.nextInt();
        int numberTwo;
        if (numberTwo=1;numberOne*numberTwo<=1000;numberTwo++){
            System.out.println("The resault of "+numberOne+" * "+numberTwo+"is: "+(numberOne*numberTwo));
        }

    }

}

2 个答案:

答案 0 :(得分:1)

如果不是循环。 是:

for (numberTwo=1;numberOne*numberTwo<=1000;numberTwo++){
    System.out.println("The resault of "+numberOne+" * "+numberTwo+"is: "+(numberOne*numberTwo));
}

答案 1 :(得分:0)

希望下面的代码有帮助

     public static void main(String[] args) {
    System.out.println("Please enter your number: ");
    Scanner keyboardInput = new Scanner(System.in);
    int numberOne = keyboardInput.nextInt();
    int numberTwo;
    for (numberTwo = 1; numberOne * numberTwo <= 1000; numberTwo++){
    System.out.println("The resault of " + numberOne + " * "
        + numberTwo + "is: " + (numberOne * numberTwo));
    }

}