使用Scanner类
代码如下:
import java.util.Scanner;
public class Kong_3 {
private static Scanner sc;
public static void main(String[] args) {
System.out.println("Input 0 to quit the program.");
sc=new Scanner(System.in);
while(true) {
System.out.println("请输入行:");
int lengthInt();
System.out.println("请输入列:");
int widthInt();
if (length==0||width==0) {
break;
}
for (int i = 1; i <= length; i++) {
System.out.print("*");
for (int j= 1; j<= width; j++) {
if (i == 1 || i == length || j== 0 || j== width)
System.out.print("*");
else {
System.out.print(" ");
}
}
System.out.println();
}
}
}
}
本文发布于:2024-02-02 21:38:09,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170688108946607.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |