用java打印一个矩形
1个回答
2013-12-24
展开全部
你好,是这样吗?import java.util.Scanner;
public class Demo1 {
public static void main(String agrs[]) {
Scanner input = new Scanner(System.in);
System.out.println("请输入行数");
int count = input.nextInt();
int num[] = new int[count];
for (int i = 0; i < num.length; i++) {
System.out.print("*");
}
System.out.println("");
for (int j = 0; j < num.length - 2; j++) { for (int i = 0; i < num.length; i++) {
if (i == 0 || i == num.length - 1) {
System.out.print("*");
} else {
System.out.print(" ");
}
}
System.out.println(" ");
}
for (int i = 0; i < num.length; i++) {
System.out.print("*");
}
}
}
public class Demo1 {
public static void main(String agrs[]) {
Scanner input = new Scanner(System.in);
System.out.println("请输入行数");
int count = input.nextInt();
int num[] = new int[count];
for (int i = 0; i < num.length; i++) {
System.out.print("*");
}
System.out.println("");
for (int j = 0; j < num.length - 2; j++) { for (int i = 0; i < num.length; i++) {
if (i == 0 || i == num.length - 1) {
System.out.print("*");
} else {
System.out.print(" ");
}
}
System.out.println(" ");
}
for (int i = 0; i < num.length; i++) {
System.out.print("*");
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询