Ver Mensaje Individual
  #1 (permalink)  
Antiguo 30/05/2012, 13:23
gobodeath
 
Fecha de Ingreso: marzo-2012
Mensajes: 75
Antigüedad: 12 años, 1 mes
Puntos: 3
Pregunta Como hacer un rombo con java?

Hola, necesito hacer la siguiente figura

---x---
--x-x--
-x---x-
x--0--x
-x---x-
--x-x--
---x---

un cuadrado de base de base y altura = 7
miren así fue como yo lo hice
pero no se que error tengo ayuda porfavor

Código Javascript:
Ver original
  1. public class ROMBO {
  2.    
  3.         public static void main(String[] args) {
  4.             int n=7;
  5.             int m=n/2+1;
  6.             int t=m-1;
  7.             int r=m+1;
  8.            
  9.             for(int i=1; i<=n; i++){
  10.                 if(i<m){
  11.                     r--;
  12.                     t++;
  13.                     for(int j=1; j<=n; j++){
  14.                         if(j==r || j==t || j==m){
  15.                             System.out.print("*");
  16.                         }else{
  17.                             System.out.print(" ");
  18.                         }
  19.                     }
  20.                 }else{
  21.                 r++;
  22.                 t--;
  23.                     for(int k=1; k<=n; k++){
  24.                      if(k==r || k==t || k==m){
  25.                          System.out.print("*");
  26.                      }else{
  27.                          System.out.print(" ");
  28.                      }
  29.                     }
  30.                 }
  31.                 System.out.println("");
  32.       }
  33.    }
  34. }