私が現在行っている作業では、「*」をアウトラインとして印刷し、「.」を印刷して正方形を「描く」必要があります。コードは機能しているようですが、まだ受け入れられません。私は初心者です、ありがとう。
class Main {
public static void main(String args[]) {
int square = 5;
int line = 1;
int stars = 1;
int startLine = square / square;
while (line <= startLine) {
while (stars <= square) { // first line prints out dots for the value of square, in this case 5
System.out.print("*");
stars = stars + 1;
}
System.out.println();
line = line + 1; //prints new line and adds 1 to line. Meaning it will move to the next section as it is now greater than startLine
}
stars = 1; //resets stars
while (line <= square - 1) {// line will keep looping until its value is greater than square - 1
while (stars <= startLine) {
System.out.print("*"); // First character to print is *
stars = stars + 1;
}
while (stars <= square - 1) {
System.out.print("."); //prints 3 dots
stars = stars + 1;
}
while (stars <= square) {
System.out.print("*"); // stars is equal to square so 1 star is printed
stars = stars + 1;
}
stars = 1;
System.out.println();
line = line + 1; // adds a value and loops around again
}
stars = 1;
while (line <= square) {
while (stars <= square) {
System.out.print("*");
stars = stars + 1;
}
System.out.println();
line = line + 1;
}
}
}
正方形を構成しているようで、「正方形」の値を変更するとサイズも変更されます。問題がわかりません。