A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

© yw201605 中级黑马   /  2016-7-4 16:57  /  397 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

import java.util.Scanner;

class FunctionTest5 {
        public static void main(String[] args) {
                //创建对象
                Scanner sc = new Scanner(System.in);
               
                System.out.println("请输入n的值:(1~9)");
                int n = sc.nextInt();
               
                //调用
                printNN(n);
        }
       
        //需求:输出对应的nn乘法
        //返回值类型:void
        //参数列表:int n
       
        public static void printNN(int n) {
                for(int x=1; x<=n; x++) {
                        for(int y=1; y<=x; y++) {
                                System.out.print(y+"*"+x+"="+y*x+"\t");
                        }
                        System.out.println();
                }
        }
}

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马