Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

My assignment is to make a house using for loops. The house should look like this

    *      
  *****
*********
*********
****  ***
****  ***

so far i only have this

for (int i=1; i<10; i += 4)
    {

      for (int j=0; j<i; j++)
      {
        System.out.print("*");
      }
      System.out.println("");
    }
  }
}
like image 902
Michael Johnson Avatar asked Nov 03 '22 03:11

Michael Johnson


1 Answers

The simplest decision will be:

    for (int y = 0; y < 6; y++) {
        int shift = y < 2 ? 4 / (y + 1) : 0;
        for (int x = 0; x < 9 - shift; x++) System.out.print(x >= shift && (y < 4 || (x < 4 || x > 5)) ? "*" : " ");
        System.out.println();
    }
like image 147
Andremoniy Avatar answered Nov 15 '22 13:11

Andremoniy