Source code :
import java.util.Scanner;
public class NewMain11 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.print("N : ");
int n = in.nextInt();
int a = n, c = n * 2 - 1, d = 0;
for (int i = 0; i < c; i++) {
for (int j = 0; j < c; j++) {
for (int k = 0; k <= i; k++) {
if (j == k || i == k || j == c - (k + 1) || i == c - (k + 1)) {
d = a - k;
break;
}
}
System.out.printf("%-4d", d);
}
System.out.println();
}
}
}
Output :
Tidak ada komentar:
Posting Komentar