Odpowiedź :
public class Zadanie3{
public static void main(String []args){
int n = 4;
// czworokat
int a = 0;
while(a < n)
{
for(int i = 0; i < n; i++)
System.out.print("*");
System.out.println();
a++;
}
// trojkat po lewej
System.out.println();
int b = 1;
do
{
for(int k = 0; k < b; k++)
System.out.print("*");
for(int j = n - b; j > 0; j--)
System.out.print(" ");
System.out.println();
b++;
} while(b <= n);
// trojkat po prawej
System.out.println();
for(int i = 1; i <= n; i++)
{
for(int j = n - i; j > 0; j--)
System.out.print(" ");
for(int k = 0; k < i; k++)
System.out.print("*");
System.out.println();
}
// piramida
System.out.println();
int totalRows = n + n - 1;
for (int currRow = 1; currRow <= totalRows; currRow += 2) {
String output = "";
n--;
for (int i = 0; i < n; i++) output += ' ';
for (int i = 1; i <= currRow; i++) output += '*';
System.out.println(output);
}
}
}