机科学教育周”正式启动,奥巴马编写了很简单的计算机代码:在屏幕上画一个正方形。现在你也跟他一起画吧!
说明:请严格按照题面说明输出即可,不必与样例格式对应
输入在一行中给出正方形边长N(3<=N<=20)和组成正方形边的某种字符C,间隔一个空格。
输出由给定字符C画出的正方形。但是注意到行间距比列间距大,所以为了让结果看上去更像正方形,我们输出的行数实际上是列数的50%
(四舍五入取整)。
10 a
aaaaaaaaaa a a a a a a aaaaaaaaaa
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int N = scanner.nextInt(); char c = scanner.next().charAt(0); for (int i = 0; i < (N + 1) / 2; i++) { for (int j = 0; j < N; j++) { if(i == 0 || j == 0 || i == ((N+1)/2 - 1) || j == N-1) { System.out.print(c); } else { System.out.print(" "); } } System.out.println(); } } }
import java.util.*; public class Main { public static void main(String[] args) { Scanner in=new Scanner(System.in); int N=in.nextInt(); char C=in.next().charAt(0); for(int i=0;i<Math.round((float) N/2.0);i++) { if(i%((N-1)/2)==0) {for (int j=0;j<N;j++) System.out.print(C); System.out.println(); continue;} for(int k=0;k<N;k++) {if(k%(N-2)==0) System.out.print(C); System.out.print(" ");} System.out.println(); } } }
import java.util.Scanner; public class WithObaMaProgram { public static void main(String args[]) { Scanner sc = new Scanner(System.in); while (sc.hasNext()) { int a = sc.nextInt(); String s = sc.next(); for (int i = 0; i < a; i++) { System.out.print(s); } System.out.println(); for (int i = 0; i < Math.ceil(a) / 2 - 2; i++) { System.out.print(s); for (int j = 0; j < a - 2; j++) { System.out.print(" "); } System.out.println(s); } for (int i = 0; i < a; i++) { System.out.print(s); } } } }
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner input=new Scanner(System.in); int size=input.nextInt(); char c=input.next().charAt(0); char[][] arr=new char[size/2+size%2][size]; for(int i=0;i<arr.length;i++){ for(int j=0;j<arr[i].length;j++){ arr[i][j]=c; } } for(int i=1;i<arr.length-1;i++){ for(int j=1;j<arr[i].length-1;j++){ arr[i][j]=' '; } } for(int i=0;i<arr.length;i++){ for(int j=0;j<arr[i].length;j++){ System.out.print(arr[i][j]); } System.out.println(); } } }
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
String str = in.next();
int length = 0;
if(n%2==0){
length = n/2;
}else{
length = n/2 + 1;
}
for(int i=0;i<length;i++) {
for (int j = 0; j < n; j++) {
if (i== 0 || i == (length - 1)) {
int s = n - 1;
while (s >= 0) {
System.out.print(str);
s--;
}
System.out.println();
break;
} else {
if (j == 0) {
System.out.print(str);
} else if (j == (n - 1)) {
System.out.println(str);
} else {
System.out.print("s");
}
}
}
}
}
}
import java.util.Scanner;public class Pat_1026 { private int N;//长方形边长 private String symbol;//符号 private int row;//除去上下边后的行数//获取边长、符号、计算rowpublic Pat_1026() { Scanner sc = new Scanner(System.in); this.N = sc.nextInt(); this.symbol = sc.next(); this.row = N / 2 - 2; if (N % 2 != 0) this.row = N / 2 + 1 - 2; sc.close(); }public void paint() { // 画行 for (int i = 0; i < N; i++) { System.out.print(symbol); } System.out.println(); // 画列 for (int j = 0; j < row; j++) { for (int count = 0; count < N ; count++) {//在第一列与最后一列画符号,注意,写空格需要使用else,如果没有else,需要修改count的 //值,且要注意每行最后面是否还会多打印一个空格,多打印的话,格式错误 if (count == 0 || count == N - 1) System.out.print(symbol); else System.out.print(" "); } System.out.println(); } // 画行 for (int i = 0; i < N; i++) { System.out.print(symbol); } }public static void main(String[] args) { Pat_1026 main = new Pat_1026(); main.paint(); } }
}