11 thoughts on “Código Java – Pirámide Numérica

  1. alguien sabe como programar asi estos numeros cuando llegue a 10 se pueda invertir ciclo
    1
    12
    123
    1234
    12345
    123456
    1234567
    12345678
    123456789
    12345678910 hasta aqui tengo codigo del programa no se como hacer esto lo uqe le siguee

    123456789
    12345678
    1234567
    123456
    12345
    1234
    123
    12
    1
    no se como invertir ciclo

  2. int nfilas = 17;
    int[] a = new int[1];

    System.out.println(“La piramide numerica”);
    System.out.println();

    for (int i=1; i<=nfilas; i+=2) {
    for(int k=i-12;k<=4;k++) {
    System.out.print(" ");
    }
    int[] x = new int[i];
    for (int j=0; j<i; j++) {

    if (j==0 || j==(i-1)) {
    x[j]=1;
    }
    else{
    if (j==1 || j==(i-2)) {
    x[j]=2;
    }
    else{
    if (j==2 || j==(i-3)) {
    x[j]=3;
    }
    else{
    if (j==3 || j==(i-4)) {
    x[j]=4;
    }
    else{
    if (j==4 || j==(i-5)) {
    x[j]=5;
    }
    else{
    if (j==5 || j==(i-6)) {
    x[j]=6;
    }
    else{
    if (j==6 || j==(i-7)) {
    x[j]=7;
    }
    else{
    if (j==7 || j==(i-8)) {
    x[j]=8;
    }
    else{
    if (j==8 || j==(i-9)) {
    x[j]=9;
    }
    }
    }
    }
    }
    }
    }
    }
    }
    if(x[j]<10) {
    System.out.print(x[j]+" ");
    }
    }
    a = x;
    System.out.println();
    }
    System.out.println();

    1. import javax.swing.JOptionPane;

      public class numeros {

      public static void main(String[] args) {
      int nfilas = 17;
      int[] a = new int[1];

      System.out.println(“La piramide numerica”);
      System.out.println();
      String texto = JOptionPane.showInputDialog(“Escribe una altura”);
      int altura = Integer.parseInt(texto);
      creaEscalera(altura);

      }

      public static void creaEscalera(int altura) {
      int[] a = new int[1];
      int nfilas = 17;

      for (int i = 1; i <= nfilas; i += 2) {
      for (int k = i – 12; k <= 4; k++) {
      System.out.print(" ");
      }
      int[] x = new int[i];
      for (int j = 0; j < i; j++) {

      if (j == 0 || j == (i – 1)) {
      x[j] = 1;
      } else {
      if (j == 1 || j == (i – 2)) {
      x[j] = 2;
      } else {
      if (j == 2 || j == (i – 3)) {
      x[j] = 3;
      } else {
      if (j == 3 || j == (i – 4)) {
      x[j] = 4;
      } else {
      if (j == 4 || j == (i – 5)) {
      x[j] = 5;
      } else {
      if (j == 5 || j == (i – 6)) {
      x[j] = 6;
      } else {
      if (j == 6 || j == (i – 7)) {
      x[j] = 7;
      } else {
      if (j == 7 || j == (i – 8)) {
      x[j] = 8;
      } else {
      if (j == 8 || j == (i – 9)) {
      x[j] = 9;
      }
      }
      }
      }
      }
      }
      }
      }
      }
      if (x[j] < 10) {
      System.out.print(x[j] + " ");
      }
      }
      a = x;
      System.out.println();
      }
      System.out.println();
      }
      }

  3. como hacer que el abecedario vaya eliminando letras pero que tambien lleve numero de lineas. Ejemplo: 1.- abcdefghijklmnopqrstuvwxyz
    2.-bcdefghijklmnopqrstuvwxyz
    3.-cdefghijklmnopqrstuvwxyz
    y ahora invertido

Deja un comentario