Rombo en Java
Muy buenas !! Soy estudiante de ASI y me han mandao de trabajo de Navidad un programa que dibuje por pantalla un Rombo de asteriscos...yo controlo C++ pero de Java no tengo ni idea.Supongo que este programilla para la mayoria de vosotros sera muy facil.Si alguien me puede mandar el codigo del programa al correo me haria 1000 favores.Muchas Gracias,hasta la vista !!!
OJALA TE SIRVA
public class Ejer_5_20
{
public static void main (String [] args)
{
for (int fila = 1; fila <= 5; fila++)
{
for (int espacio = 4; espacio >= fila; espacio--)
System.out.print(" ");
for (int aste = 1; aste <= (fila * 2) - 1; aste++)
System.out.print("*");
System.out.print("n");
}
for (int fila = 4; fila >= 1; fila--)
{
for (int espacio = 4; espacio >= fila; espacio--)
System.out.print(" ");
for (int aste = 1; aste <= (fila * 2) - 1; aste++)
System.out.print("*");
System.out.print("n");
}
}
}
public class Ejer_5_20
{
public static void main (String [] args)
{
for (int fila = 1; fila <= 5; fila++)
{
for (int espacio = 4; espacio >= fila; espacio--)
System.out.print(" ");
for (int aste = 1; aste <= (fila * 2) - 1; aste++)
System.out.print("*");
System.out.print("n");
}
for (int fila = 4; fila >= 1; fila--)
{
for (int espacio = 4; espacio >= fila; espacio--)
System.out.print(" ");
for (int aste = 1; aste <= (fila * 2) - 1; aste++)
System.out.print("*");
System.out.print("n");
}
}
}
<code>
public class Rombo {
private static final char rhombusCharacter = '*';
private static final char whitespaceCharacter = '-';
public static void main(String[] args) {
int totalLength = 20;
int currentLength = 1;
do {
System.out.println(getLine(currentLength, totalLength));
} while((currentLength+=2) < totalLength);
while((currentLength-=2) > 0) {
System.out.println(getLine(currentLength, totalLength));
}
}
private static String getLine(int rhombusLength, int totalLength) {
StringBuffer line = new StringBuffer(totalLength);
int whitespaces = (totalLength - rhombusLength) / 2;
for (int x = 0; x < whitespaces; ++x) {
line.append(whitespaceCharacter);
}
line.append(rhombusCharacter);
if (rhombusLength > 1) {
for (int x = 2; x < rhombusLength; ++x) {
line.append(whitespaceCharacter);
}
line.append(rhombusCharacter);
}
for (int x = 0; x < whitespaces; ++x) {
line.append(whitespaceCharacter);
}
return line.toString();
}
}
</code>
public class Rombo {
private static final char rhombusCharacter = '*';
private static final char whitespaceCharacter = '-';
public static void main(String[] args) {
int totalLength = 20;
int currentLength = 1;
do {
System.out.println(getLine(currentLength, totalLength));
} while((currentLength+=2) < totalLength);
while((currentLength-=2) > 0) {
System.out.println(getLine(currentLength, totalLength));
}
}
private static String getLine(int rhombusLength, int totalLength) {
StringBuffer line = new StringBuffer(totalLength);
int whitespaces = (totalLength - rhombusLength) / 2;
for (int x = 0; x < whitespaces; ++x) {
line.append(whitespaceCharacter);
}
line.append(rhombusCharacter);
if (rhombusLength > 1) {
for (int x = 2; x < rhombusLength; ++x) {
line.append(whitespaceCharacter);
}
line.append(rhombusCharacter);
}
for (int x = 0; x < whitespaces; ++x) {
line.append(whitespaceCharacter);
}
return line.toString();
}
}
</code>
