JAVA
java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import java.io.*;
import java.util.*;
public class Solution {
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
Scanner sc = new Scanner(System.in); //Scanner statement
int n = sc.nextInt(); //read number of rows from user
char x = sc.next().charAt(0); //read symbol from user
int i, j, k, count=n/2; //declare integer variables
if (n%2 != 0){ //this code runs when input is odd
n=n-1;
for (i=0; i <= n; i++){ //this loop controls number of rows
for (j=0; j < 1; j++){ //this loop controls number of columns
System.out.print(x);
}
for (k=0; k<=n/2; k++){ //this loop controls number of spaces
if (k==count && k!=0){ //if space number equals count,
System.out.print(x); //print symbol
} else {
System.out.printf(" "); //print space
}
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run