题解 | #牛牛的字符菱形#
牛牛的字符菱形
https://www.nowcoder.com/practice/11a5040fa894430f9d25fda1be37ddc8
import java.util.Scanner; public class Main { public static void main(String[] args) { //输入你要打印的字符 Scanner in = new Scanner(System.in); char c1 = in.next().charAt(0); int n = 3; for (int i = 1; i <= n; i++) { //打印空白 for (int j = 1; j <= n - i; j++) { System.out.print(" "); } //打印你输入的字符 for (int k = 1; k <= 2 * i - 1; k++) { System.out.print(c1); } System.out.print("\n"); } //开始打印下面的 for (int i1 = 1; i1 <= n - 1; i1++) { for (int j1 = 1; j1 <= i1; j1++) { System.out.print(" "); } for (int k1 = 1; k1 <= n - 2 * (i1 - 1); k1++) { System.out.print(c1); } System.out.print('\n'); } } }
好好去研究