Java编程-四种方式实现九九乘法表()

2019-11-04  本文已影响0人  沐诗卉
1.png

public class test1 {

public static void main(String[] args) {
    // TODO Auto-generated method stub
    for(int i=1;i<=9;i++)
    {
         for(int j=1;j<=i;j++)
         {
             System.out.print(i+"*"+j+"="+(i*j)+"  ");
         }
         System.out.println();
        
    }
}

}

2.png

public class test2 {

public static void main(String[] args) {
    // TODO Auto-generated method stub
    for (int i = 1; i <= 9; i++) {// 控制行
        // 用来控制每行空格的数量
        for (int k = 1; k <= 9 - i; k++) {
        System.out.print("     \t");
    }
    for (int j = 1; j <= i; j++) {// 控制列
        System.out.print(j + "*" + i + "=" + (i * j) + "\t");
        }
    System.out.println();
    }
}

}

3.png

public class test3 {

public static void main(String[] args) {
    // TODO Auto-generated method stub
    for (int i = 9; i >= 1; i--) {
        for (int k = 1; k <= 9 - i; k++) {
                System.out.print("     \t");
        }
        for (int j = 1; j <= i; j++) {
            System.out.print(j + "*" + i + "=" + (i * j) + "\t");
        }
        System.out.println();
    }
}

}

4.png

public class test4 {

public static void main(String[] args) {
    // TODO Auto-generated method stub
    for (int i=9; i>=1; i--) {
        for (int j=1; j<=i; j++) {
            System.out.print(j+"*"+i+"="+(i*j)+"\t");
        }
        System.out.println();
    }
}

}

上一篇下一篇

猜你喜欢

热点阅读