chilly-night

1

双for打印99乘法表,和for+if打印99乘法表。

public class Multiplication_table {
    public static void main(String[] args) {
        System.out.println("我是用双for写的:");
        for (int j = 1; j < 10; j++) {
            for (int i = 1; i <= j; i++) {
                System.out.print(i + "*" + j + "=" + i * j + "\t");
            }
            System.out.println();
        }
        Multiplication_2 m2 = new Multiplication_2();
        m2.test_if();
    }
}
//第二种方法
class Multiplication_2 {
    public void test_if() {
        System.out.println("我是用for+if写的:");
        for (int i = 1, j = 1; i < 10; ) {
            if (i > j) {
                System.out.print(i + "*" + j + "=" + i * j + "\t");
            } else if (i < j) {
                if (i == 1) {
                    System.out.println();
                }
                System.out.print(i + "*" + j + "=" + i * j + "\t");
                i++;
            } else {
                System.out.print(i + "*" + j + "=" + i * j + "\t");
                i = 1;
                j++;
                if (j > 9) {
                    break;
                }
            }
        }
    }
}

感谢观看,求一个赞❤

分类:

技术点:

相关文章:

  • 2021-12-09
  • 2021-12-09
  • 2021-12-09
  • 2021-12-09
  • 2021-12-09
  • 2021-12-09
  • 2022-01-09
  • 2021-06-28
猜你喜欢
  • 2022-01-26
  • 2022-12-23
  • 2021-12-09
  • 2021-08-11
  • 2021-12-09
  • 2021-12-09
  • 2021-12-09
相关资源
相似解决方案