Advertisement
Guest User

Untitled

a guest
Oct 24th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1.  
  2. /**
  3. * Created by SBT-Strelnikov-AN on 13.10.2016.
  4. */
  5. public class Test {
  6. final static int MAX_HEIGHT = 23;
  7. final static int MIN_HEIGHT = 1;
  8. public static void main(String[] args){
  9. Scanner in = new Scanner(System.in);
  10. int height = in.nextInt();
  11. while(height<MIN_HEIGHT || height>MAX_HEIGHT){
  12. System.out.println("Wrong height, please reenter data");
  13. height = in.nextInt();
  14. }
  15. int width = height+1;
  16. System.out.println(makePyramid(width-2, 2, height));
  17. }
  18.  
  19. public static String makePyramid(int spaces, int symbols, int heigh){
  20. StringBuilder builder = new StringBuilder();
  21. if(heigh==0){
  22. return "";
  23. }
  24. builder.append(generateSymboSequence(' ', spaces)).append(generateSymboSequence('#',symbols)).append("\n");
  25. return builder.append(makePyramid(spaces-1,symbols+1,heigh-1)).toString();
  26. }
  27.  
  28. public static String generateSymboSequence(char symbol, int times){
  29. StringBuilder builder = new StringBuilder();
  30. for(int i=0;i<times;i++){
  31. builder.append(symbol);
  32. }
  33. return builder.toString();
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement