package demo;
import java.util.Scanner;
public class HalfDaimond
{
public static void main(String[] args)
{
int num, q;
Scanner sc = new Scanner(System.in);
System.out.print("Enter Seeding Number : ");
num = sc.nextInt();
for (int r = 1, n = num; r <= num; r++, n--) {
for (int c = r, p = n; c >= 1; c--, p++) {
System.out.print(p);
}
for (int c = r, p = num - 1; c > 1; c--, p--) {
System.out.print(p);
}
System.out.println();
}
for (int r = 1; r < num; r++) {
for (int c = r, p = r + 1; c < num; c++, p++) {
System.out.print(p);
}
for (int c = num - r, p = num - 1; c > 1; c--, p--) {
System.out.print(p);
}
System.out.println();
}
}
}
Output:
Enter Seeding Number : 4
4
343
23432
1234321
23432
343
4
BUILD SUCCESSFUL (total time: 3 seconds)
No comments:
Post a Comment