数据结构与算法-打印长方形算法

2019-10-26 21:24:23 浏览数 (1)

代码语言:javascript复制
package *;

/**
 * @program: data-structure
 * @description: 长方形
 * @author: ChenWenLong
 * @create: 2019-09-10 14:54
 **/
public class Rectangle {

    public static void main(String[] args) {
        printRectangle(2,3);
    }

    /**
     * 功能描述:
     * 〈打印指定长度和宽度的,长方形〉
     *
     * @params : [length, wideth]
     * @return : void
     * @author : cwl
     * @date : 2019/9/10 14:57
     */
    public static void printRectangle(int length,int wideth) {
        if(length <= 0 || wideth <= 0){
            throw new RuntimeException("number mast greater than zero");
        }
        if (length > 1 || wideth > 1) {
            for (int i = 1; i <= length; i  ) {
                for (int j = 1; j <= wideth; j  ) {
                    System.out.print("*");
                }
                System.out.println();
            }
        } else {
            System.out.println("数字应大于1");
        }
    }
}

0 人点赞