题目描述
都说程序猿不好找妹子(不过我校的学弟学妹们可以问问学长关于鞍山GQ和志愿者的故事,以及GC把妹子发展成ACMer的故事 大连交通的传奇故事哦。真的励志~)
一天,我校ACM协会的一个学弟想要用程序员的方式给一位妹子表白。想写程序打印个"I love U"
但这个字母U实在难倒了他,于是找我们的会长TL帮忙,可TL会长琐事缠身,你能替TL帮助这位学弟吗?
输入
多行测试数据,每行包含一个整数a(0<a<100),表示U的大小
输出
输出对应大小的U,每两个U之间,要有一个空行
样例输入
1 2 3
样例输出
* * *** * * * * **** * * * * * * *****
一.
import java.util.Scanner;
public class Main1 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while (scanner.hasNext()) {
int a = scanner.nextInt();
for (int i = 0; i < a; i++) {
System.out.print("*");
for (int j = 0; j < a; j++) {
System.out.print(" ");
}
System.out.print("*\n");
}
for (int i = 0; i < a+2; i++) {
System.out.print("*");
}
System.out.print("\n\n");
}
}
}
二
import java.util.Scanner;
public class Main1 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while (scanner.hasNext()) {
int a = scanner.nextInt();
for (int i = 0; i < a; i++) {
for (int j = 0; j < a + 2; j++) {
if (j == 0 || j == a + 1)
System.out.print("*");
else
System.out.print(" ");
}
System.out.print("\n");
}
for (int i = 0; i < a + 2; i++)
System.out.print("*");
System.out.print("\n\n");
}
}
}
两种方法实质性是一样的都是分两个阶段 一个打印上层依次增加层 一个打印最后一层依次增加的*