int height = 5;
int width = 8;
for(int y = 0;y<=height;y++){
for(int x=0; x<=width;x++){
if(((y ==0) || (y==height) ||(x == 0)) && (x!=width)){
System.out.print("*");
continue;
}
if( x == width ){
System.out.println("*");
continue;
}
System.out.print(" ");
}
}
本文提供了一个使用Java编程语言绘制矩形边界的简单示例。通过双重循环遍历高度和宽度,仅在矩形的边界上打印星号(*)字符,而在内部则留空。这种实现方式有助于初学者理解如何在控制台上输出特定形状。
336

被折叠的 条评论
为什么被折叠?



