Computer Science, asked by bhavyamalhotra1902, 7 months ago

what is the logic in java to get the output for
*
*1*
*121*
*12321*
*121*
*1*
*

Answers

Answered by r30499699
0

import java.io.*;

import java.util.*;

public class Program {

public static void main(String []args) {

Scanner in = new Scanner(System.in);

System.out.print("Enter a number: ");

int n=in.nextInt();

for(int i=1;i<=n;i++) {

for(int j=i;j<=n-1;j++) {

System.out.print(" ");

}

for(int j=1;j<=i;j++) {

System.out.print(j);

}

for(int j=i-1;j>=1;j--) {

System.out.print(j);

}

System.out.println();

}

}

}

Output:

$ java Program

Enter a number: 4

1

121

12321

1234321

Similar questions