题解 | #菱形图案#
菱形图案
https://www.nowcoder.com/practice/8b935f8ffe99445dbd42494febd13e45
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNext()) { int n = sc.nextInt(); //上三角 for (int c = 0; c < n; c++) { for (int a = n - c ; a > 0; a--) { System.out.print(" "); } for (int b = 0; b <= c; b++) { System.out.print("* "); } System.out.println(); } //中间线 for (int s = 0; s <= n; s++) { System.out.print("* "); } System.out.println(); //下三角 for (int c = 0; c < n; c++) { for (int b = 0; b <= c; b++) { System.out.print(" "); } for (int a = n - c ; a > 0; a--) { System.out.print("* "); } System.out.println(); } } } }
#Java找工作#