當前位置:編程學習大全網 - 編程軟體 - 有壹個JAVA程序可以打印壹個矩形!

有壹個JAVA程序可以打印壹個矩形!

公共類RectangleDemo {

私有靜態int M = 20

私有靜態int N = 18;

私有int m;//長度

私有int n;//寬度

RectangleDemo(int m,int n) {

如果(m & gt0)this . m = m;

else this.m = M

如果(n & gt0)this . n = n;

else this.n = N

}

公共作廢打印(){

for(int I = 0;我& ltn;i++) {

if (i == 0 || i == n - 1) {

for(int j = 0;j & ltm;j++) {

if (j == 0 || j == m - 1)

system . out . print(" | ");

其他

system . out . print("-");

}

}否則{

for(int j = 0;j & ltm;j++) {

if (j == 0 || j == m - 1)

system . out . print(" | ");

其他

system . out . print(" ");

}

}

system . out . println();

}

}

公共靜態void main(String[] a) {

rectangle demo re = new rectangle demo(20,8);

re . print();

}

}

結果

如果要以' * '為邊,就把輸出改成*。

  • 上一篇:關於西門子PLC S7-300
  • 下一篇:展廳設計師是做什麽的
  • copyright 2024編程學習大全網