Foro de elhacker.net

Programación => Java => Mensaje iniciado por: andaluz en 8 Abril 2010, 18:55 pm



Título: ayuda con codigo
Publicado por: andaluz en 8 Abril 2010, 18:55 pm
me gustaria que me ayudaseis a poder resolver este codigo, ya que no me hace las lineas horizontalesy el bucle que me hace es infinito, espero que me podais ayudar.

Código
  1. package escalera;
  2.  
  3. public class Main
  4. {
  5.    final static int LONGITUD=30;
  6.    final static char CARACTER='*';
  7.    final static int ANCHOESC=5;
  8.    final static int ALTOESC=3;
  9.    final static int NUMESC=7;
  10.  
  11.    public static void main(String[] args)
  12.    {
  13.        int i,j,k,z;
  14.        int desp=0;
  15.        System.out.print("\n");
  16.        for(k=1;k<=NUMESC;k++)
  17.        {
  18.            for(z=0;z<desp*(ANCHOESC-1);z++)
  19.            {
  20.                System.out.print(' ');
  21.            }
  22.            for(i=0;i<ANCHOESC;i++)
  23.            {
  24.                System.out.print("\n");
  25.                for(i=0;i<ALTOESC;i++)
  26.                {
  27.                    for(j=0;j<(desp+1)*(ANCHOESC-1);j++)
  28.                    {
  29.                        System.out.print(' ');
  30.                    }
  31.                    System.out.print(CARACTER+"\n");
  32.                }
  33.                desp++;
  34.            }
  35.        }
  36.    }
  37. }
  38.  


Título: Re: ayuda con codigo
Publicado por: kasiko en 9 Abril 2010, 00:20 am
hola

a ver si te vale este codigo....

Código:
package escalera;

/**
 *
 * @author Kasiko
 */
public class ejer
{
    final static int LONGITUD=30;
    final static char CARACTER='*';
    final static int ANCHOESC=5;
    final static int ALTOESC=3;
    final static int NUMESC=7;

    /**
     *
     * @param args
     */
    public static void main(String[] args)
    {
        int i,j,k,z;
        int desp=0;
        System.out.print("\n");
        for(k=1;k<=NUMESC;k++)
        {
         for(i=1;i<=ANCHOESC+desp;i++)
         {
             System.out.print(CARACTER);
         }
         System.out.println();
         desp+=ANCHOESC;
         for(i=1;i<=ALTOESC;i++){
             for(j=1;j<=desp;j++)
             {
                 System.out.print(" ");
             }
             System.out.println(CARACTER);
            }
        // System.out.print(CARACTER);
        }
    }
}