View Code of Problem 2592

import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int t = scanner.nextInt();
		for(int i=0; i<t; i++) {
			String s = scanner.next();
			int n = scanner.nextInt();
			for(int j=0; j<n; j++) {
				for(int k=0; k<n-j-1; k++) {
					System.out.print(" ");
				}
				System.out.print(s);
				if(j>0) {
					if(j+1 != n) {
						for(int k=0; k<((j-1)*2+1); k++) {
							System.out.print(" ");
						}
					}else {
						for(int k=0; k<(j-1)*2+1; k++) {
							System.out.print(s);
						}
					}
					System.out.println(s);
				}else {
					System.out.println();
				}
			}
		}
	}
}

Double click to view unformatted code.


Back to problem 2592