PROBLEM 2 : BUILD A PYRAMID
Build a pyramid is not an easy job.
But as a computer experts you are able to build a pyramid within a
second. Your task is to enter a number and a character. The material
of the pyramid is the character’s entered while the height of the
pyramid is the number’s entered.
Input
The first line of the input contains
an integer N (1 ≤ N ≤ 5), the number of test cases. Following the
first line are the test cases. Each line of a test case contains a
non-negative integer number and a character separated by a single
space. The non-negative number is smaller than 10 and the character
is could be a number, alphabet or symbol.
The input must be read from standard
input.
Output
The output of the program should
display the design of the pyramid.
The output must be written to standard
output.
Sample
Input
|
Sample
Output
|
3
2
*
5
^
3
@
|
*
* *
^
^ ^
^ ^ ^
^ ^ ^ ^
^ ^ ^ ^ ^
@
@ @
@ @ @
|
Solution :
import java.util.*;
public class pyramid {
public static void main(String [] args) {
Scanner scan = new Scanner(System.in);
int no = scan.nextInt();
for(int a=0;a<no;a++) {
int num = scan.nextInt();
String s = scan.next();
int t=num;
for(int x=1;x<=num;x++) {
for(int y=t; y>0; y--)
System.out.print(" ");
for(int z=0; z<x; z++)
System.out.print(s+" ");
System.out.println("");
t--;
}
System.out.println("\n\n");
}
}
}