【程式語言】JAVA的第四堂課 |印出 X 字形 (print pattern X)
Published:
by .import java.util.Scanner;
public class ch4 {
public static void main(String[] args){
int n,i,j;
System.out.print("Input n:");
Scanner input = new Scanner(System.in);
n = input.nextInt();
for(i=0; i < n ; i++) {
for(j=0 ; j<n ; j++) {
if (i%(n-1) == 0 || i==j || i+j==(n-1)) {
System.out.print("$");
}
else {
System.out.print(" ");
}
}
System.out.println("");
}
}
}