题解 | #X形图案#
X形图案
https://www.nowcoder.com/practice/83d6afe3018e44539c51265165806ee4
import java.util.Scanner; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); // 注意 hasNext 和 hasNextLine 的区别 while (in.hasNextInt()) { // 注意 while 处理多个 case int a = in.nextInt(); int f = a,f1 = 0,f2 = a-1; for(int i = 0;i < a;i++){//打印上半部分 for(int j = 0;j<f;j++){//一行 if(j == f1){ System.out.print("*"); } else if(j==f2){ System.out.print("*"); } else{ System.out.print(' '); } } System.out.printf("\n"); f1++;f2--; } } } }