- /*
- 根据键盘录入的数据输出九九乘法表
- 通过方法实现
- */
- import java.util.Scanner;
- class Test1_Method {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- System.out.println("请输入一个1-9的整数:");
- int x = sc.nextInt();
- print99(x);
- }
- public static void print99(int x) {
- if (x <1 || x > 9) {
- System.out.println("录入的值不合法");
- } else {
- for (int a = 1; a <= x; a++) {
- for (int b =1; b <= a; b++) {
- System.out.print(b + " * " + a + " = " + a*b + '\t');
- }
- System.out.println();
- }
- }
- }
- }
复制代码 |
|