Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Created by SBT-Strelnikov-AN on 13.10.2016.
- */
- public class Test {
- final static int MAX_HEIGHT = 23;
- final static int MIN_HEIGHT = 1;
- public static void main(String[] args){
- Scanner in = new Scanner(System.in);
- int height = in.nextInt();
- while(height<MIN_HEIGHT || height>MAX_HEIGHT){
- System.out.println("Wrong height, please reenter data");
- height = in.nextInt();
- }
- int width = height+1;
- System.out.println(makePyramid(width-2, 2, height));
- }
- public static String makePyramid(int spaces, int symbols, int heigh){
- StringBuilder builder = new StringBuilder();
- if(heigh==0){
- return "";
- }
- builder.append(generateSymboSequence(' ', spaces)).append(generateSymboSequence('#',symbols)).append("\n");
- return builder.append(makePyramid(spaces-1,symbols+1,heigh-1)).toString();
- }
- public static String generateSymboSequence(char symbol, int times){
- StringBuilder builder = new StringBuilder();
- for(int i=0;i<times;i++){
- builder.append(symbol);
- }
- return builder.toString();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement