1910李周聪


私信TA

用户名:lzx1904071030

访问量:878

签 名:

等  级
排  名 22563
经  验 596
参赛次数 0
文章发表 2
年  龄 19
在职情况 学生
学  校 湖北生物科技职业学院
专  业

  自我简介:

解题思路:

注意事项:注意格式;

参考代码:


public class Main {


/**

* @param args

*/

public static void main(String[] args) {

// TODO Auto-generated method stub

/*正确输出表头部分*/

System.out.println("  Nine-by-nine Multiplication Table");

        System.out.println("--------------------------------------");

        System.out.println("     1   2   3   4   5   6   7   8   9");

        System.out.println("--------------------------------------");

        /*循环打印部分,外循环打印行,内循环打印列*/

        for (int i = 1; i <=9; i++) {

            System.out.print(" "+i);

            for (int j = 1; j <= 9; j++) {

            /*/%4d是输出宽度为4的意思,如果宽度小于4前面将会用空格填充.

            * 比如输出量为2,则输出结果为:2(2前面有3个空格)若数值大于4位,

            * 则按实际宽度输出.*/

            System.out.printf("%4d",i*j);

            /*printf()函数是式样化输出函数 基本格式为:printf("<式样化字符串>",<参数表>)*/

                if (j==i) {

                    break;//当j==i的时跳出循环

                }

            }

            /*换行*/

            System.out.println("");

}

        /*结尾部分*/

        System.out.print("--------------------------------------");

}

}


 

0.0分

2 人评分

  评论区