Dibujar un árbol usando asteriscos con Java
Draw an asterisk tree with Java
Uno de los ejemplos clásicos de uso de ciclos en los lenguajes de programación es utilizarlos para dibujar figuras con asteriscos.
En este caso tenemos la figura de este árbol.
*
***
*****
*******
*********
***********
*************
***************
*****************
*******************
**
**
**
El código es el siguiente:
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ /** * * @author daniel */ public class DibujarArbol { public static void dibujar() { int nivel = 10; int a; int espacios; for (int i = 1; i <= nivel; i++) { StringBuffer f = new StringBuffer(); espacios = nivel - i; a = i + (i - 1); for (int i1 = 0; i1 < espacios; i1++) f.append(" "); for (int i2 = 0; i2 < a; i2++) f.append("*"); System.out.println(f.toString()); } for (int j=0; j<3 && nivel-2<(nivel/2)+1; j++){ System.out.print("*"); } System.out.println(""); } public static void main(String args[]) { DibujarArbol.dibujar(); } }
Quizá te interese :
Programa para realizar suma de polinomios con listas enlazadas. package com.ubicuos.main; im ...
Leer datos con Java Read from Console Standard Input with Java Si alguna vez, necesitaste leer ...
Árbol fractal en BorlandC para DOS /*arbol3*/ /*Fernando Galindo Soria*/ #include #incl ...









UMMM ME MARCA TRES ERRORES DE COMPILACIÓN O ALGO ASÍ…
O AL MENOS Q YO LO HAYA TIPEADO MAL ..PERO NO CREOO
CHECALO PORFA Y ASEGURAME Q ES ASÍ…Y MIENTRAS YO TRATARÉ DE VERIFICAR LOS CODIGOS
GOD BLESSES YOU
Ya está actualizado, prueba el código y nos dices si te funciona.
Espero te sirva, gracias por comentar :)
ola yo toy tratando de hacer 2 codigos k son estos
* *
* *
* *
* *
* *
* *
*
*
* * * * *
*
*
kiero k me salgan estas imagenes en java si alguien me puede ayudar
xk aun no me sale el primero si me sale peor no como kiero
luiggi.
Haz tu diseño en una cuadrícula e identifica el patrón que sigue, (partes, nones,etc.), eso te ayudará a poner las condicionales en los lugares adecuados.