【筆面試真題】2022年4月14日-攜程資料開發第三批
阿新 • • 發佈:2022-04-14
輸入n,列印u
package com.jhliu20.real; import java.util.Scanner; public class XieChengTest { public static void main(String[] args) { int n; Scanner sc = new Scanner(System.in); n = sc.nextInt(); int height = n * 4; char[][] arr = new char[height][height];for(int i = 0; i < height - n; i++) { for(int j = 0; j < n; j++) { arr[i][j] = '*'; } for(int j = height - 1, k = 0; k < n; j--) { arr[i][j] = '*'; k++; } } int f = 1; for(inti = height - n, count = n; i <= height - 1; i++) { for(int j = f; j < f + n; j++) { arr[i][j] = '*'; } for(int j = height - 1; j > (height) / 2 - 1; j--) { arr[i][j] = arr[i][height - j - 1]; } f++; }for(int i = 0; i < height; i++) { for(int j= 0; j < height; j++) { System.out.print(arr[i][j] == '*' ? '*' : '.'); } System.out.println(""); } } }