數據結構與演算法-列印長方形演算法

  • 2019 年 10 月 26 日
  • 筆記

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");          }      }  }