1036 跟奥巴马一起编程 (15分)
原题链接:传送门
一、题目:
输入样例 1:
10 a
输出样例 1:
aaaaaaaaaa
a a
a a
a a
aaaaaaaaaa
二、解析:
思路:
第一行和最后一行需要打印N个C,其他的只要首尾有C即可。两个for循环判断打印即可
AC代码:
import java.util.Scanner;
/**
* 1036 跟奥巴马一起编程 (15分)
* @思路:第一行和最后一行需要打印N个C,其他的只要首尾有C即可。两个for循环判断打印即可
* @author: ChangSheng
* @date: 2019年12月30日 下午8:27:29
*/
public class Main {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int N= s.nextInt();
String C = s.next();
int column = (int) Math.round(N/2.0);
for (int i = 0; i < column; i++) { // 行
for (int j = 0; j < N; j++) { // 列
if (i == 0 || i == column-1) {
System.out.print(C);
} else {
if (j == 0 || j == N-1) {
System.out.print(C);
} else {
System.out.print(" ");
}
}
}
System.out.println();
}
}
}