1. 삼각형 만들기
public class Triangle {
public static void main(String[] args) {
for(int i = 0 ; i < 5 ; i++) {
for(int j = 0 ; j < 5 ; j++) {
boolean b = i + j <= 4;
if (b) {
System.out.printf("[%d,%d]", i, j);
}
else {
System.out.print(" ");
}
}
System.out.println();
}
}
}
2. 역삼각형 만들기
public class Triangle2 {
public static void main(String[] args) {
for(int i = 0 ; i < 5 ; i++) {
for(int j = 0 ; j < 5 ; j++) {
boolean b = i <= j;
if (b) {
System.out.printf("[%d,%d]", i, j);
}
else {
System.out.print(" ");
}
}
System.out.println();
}
}
}
3. 마름모 만들기
public class Practice {
public static void main(String[] args) {
for (int i = 0 ; i < 5 ; i++) {
for (int j = 0 ; j < 5 ; j++) {
boolean b = i + j < 2 || i - j > 2;
boolean c = i - j > -3 && i + j < 7;
if (b) {
System.out.printf(" ");
} else if (c) {
System.out.printf("[%d,%d]", i, j);
}
}
System.out.println();
}
}
}
public class Rhombus {
public static void main(String[] args) {
for (int i = 0 ; i < 3 ; i++) {
for (int j = 0 ; j < 5 ; j++) {
boolean b = i + j < 2;
boolean c = i + 3 > j;
if (b) {
System.out.printf(" ");
} else if (c) {
System.out.printf("[%d,%d]", i, j);
}
}
System.out.println();
}
for (int i = 2 ; i > 0 ; i--) {
for (int j = 0 ; j < 5 ; j++) {
boolean b = i + j < 3;
boolean c = j - i < 2;
if (b) {
System.out.printf(" ");
} else if (c) {
System.out.printf("[%d,%d]", i, j);
}
}
System.out.println();
}
}
}
public class Rhombus2 {
public static void main(String[] args) {
int cnt = 5;
for (int i = - cnt / 2 ; i < cnt - cnt / 2 ; i++) {
for (int j = - cnt / 2 ; j < cnt - cnt / 2 ; j++) {
if (Math.abs(i) + Math.abs(j) <= cnt / 2) {
// if (i + j > 1 && i + j < 7 && i - j < 3 && j - i < 3) {
System.out.printf("[%2d,%2d]", i, j);
}
else {
System.out.printf("%7c", ' ');
}
}
System.out.println();
}
}
}