Answer the question
In order to leave comments, you need to log in
How to understand why certain shapes are drawn in cycles?
Hello guys, I just can not understand the principle of the FOR loop. Rather, I understand how it works and what it is for, I know that there is an external and internal cycle. External reads vertical, internal horizontal.
But I can’t figure out how to implement all sorts of shapes, for example, rhombuses, squares with an empty middle, etc.
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
try (Scanner tru = new Scanner(System.in)) {
int count = 10;
for (int i = 0; i < count; i++) {
for (int k = 0; k < count; k++) {
if (k == 0 || k == count - 1 || i == 0 || i == count - 1) {
System.out.print("*");
} else {
System.out.print(" ");
}
}
System.out.println(" ");
}
}
}
}
if (k == 0 || k == count - 1 || i == 0 || i == count - 1)
#********#
# #
# #
# #
# #
# #
# #
# #
# #
#********#
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question