Advertisement
AndroFan_13

Pir

Aug 30th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.67 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package librojava;
  7.  
  8. /**
  9.  *
  10.  * @author profe
  11.  */
  12. public class Pir {
  13.  
  14.     /**
  15.      * Este método construye una pirámide con el pico apuntando hacia arriba
  16.      * @param caracter es el carácter con el que se dibujará la pirámide
  17.      * @param base describe la longitud de la base
  18.      * @return
  19.      */
  20.     public static char Arriba(char caracter, int base) {
  21.         for (int x = base; x >= 1; x--) {
  22.             int a = base;
  23.             boolean controller = true;
  24.             while (controller) {
  25.                 System.out.print(" ");
  26.                 if (a + x == base) {
  27.                     controller = false;
  28.                 } else {
  29.                     controller = true;
  30.                     a--;
  31.                 }
  32.             }
  33.             int b = base;
  34.             System.out.print(caracter);
  35.             controller = true;
  36.             while (controller) {
  37.                 if (x != base) {
  38.                     System.out.print(" " + caracter);
  39.                 }
  40.                 if (b - x == 1) {
  41.                     controller = false;
  42.                 } else {
  43.                     controller = true;
  44.                     b--;
  45.                 }
  46.             }
  47.             System.out.println("");
  48.         }
  49.         return caracter;
  50.     }
  51.  
  52.     /**
  53.      * Este método construye una pirámide con el pico apuntando hacia abajo
  54.      * @param caracter es el carácter con el que se dibujará la pirámide
  55.      * @param base describe la longitud de la base
  56.      * @return
  57.      */
  58.     public static char Abajo(char caracter, int base) {
  59.         for (int x = base; x >= 1; x--) {
  60.             int a = base;
  61.             boolean controller = true;
  62.             while (controller) {
  63.                 System.out.print(" ");
  64.                 if (a - x == 0) {
  65.                     controller = false;
  66.                 } else {
  67.                     controller = true;
  68.                     a--;
  69.                 }
  70.  
  71.             }
  72.             System.out.print(caracter);
  73.             for (int y = x; y > 1; y--) {
  74.                 System.out.print(" " + caracter);
  75.             }
  76.             System.out.println("");
  77.         }
  78.         return caracter;
  79.     }
  80.  
  81.     public static char Izquierda(char caracter, int base) {
  82.         String build;
  83.         build = Character.toString(caracter);
  84.  
  85.         return caracter;
  86.     }
  87.  
  88.     public static char Derecha(char caracter, int base) {
  89.         String build;
  90.         build = Character.toString(caracter);
  91.  
  92.         return caracter;
  93.     }
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement