[Question] Draw a diamond in a rectangle

Nice to meet you. I'm new to Java. I would like to draw a diamond in a rectangle as shown below. □□□□■□□□□ □□□■■■□□□ □□■■■■■□□ □■■■■■■■□ ■■■■■■■■■ □■■■■■■■□ □□■■■■■□□ □□□■■■□□□ □□□□■□□□□

I can understand how to output ■ I tried coding up to the following using only the for statement.


public class Study1_3 { public static void main(String[] args) { for (int i = 1; i <= 10; i += 2) { for (int n = 0; n < i; n++) { System.out.print("■"); } System.out.println(); } for (int i = 1; i <= 9; i += 2) { for (int n = 0; n < 8 - i; n++) { System.out.print("■"); } System.out.println(); } } }


After that, I think that I will use the if statement to code the □ part, I'm in trouble because it doesn't work. I would be grateful if anyone could teach me.


【Additions】

It's been a long time, but I tried to code it in my own way. \\\\\\\\\\\ public class Study {

public static void main(String[] args) {

// Diamond in the rectangle for (int i = 1; i <= 9; i++) { for (int j = 1; j <= 9; j++) { if (i == 1 && j == 5 || i == 2 && j == 4 || i == 2 && j == 5 || i == 2 && j == 6 || i == 3 && j == 3 || i == 3 && j == 4 || i == 3 && j == 5 || i == 3 && j == 6 || i == 3 && j == 7 || i == 4 && j == 2 || i == 4 && j == 3 || i == 4 && j == 4 || i == 4 && j == 5 || i == 4 && j == 6 || i == 4 && j == 6 || i == 4 && j == 7 || i == 4 && j == 8 || i == 5 && j == 1 || i == 5 && j == 2 || i == 5 && j == 3 || i == 5 && j == 4 || i == 5 && j == 5 || i == 5 && j == 6 || i == 5 && j == 5 || i == 5 && j == 7 || i == 5 && j == 5 || i == 5 && j == 8 || i == 5 && j == 9 || i == 6 && j == 2 || i == 6 && j == 3 || i == 6 && j == 4 || i == 6 && j == 5 || i == 6 && j == 6 || i == 6 && j == 7 || i == 6 && j == 8 || i == 7 && j == 3 || i == 7 && j == 4 || i == 7 && j == 5 || i == 7 && j == 6 || i == 7 && j == 7 || i == 8 && j == 4 || i == 8 && j == 5 || i == 8 && j == 6 || i == 9 && j == 5) { System.out.print("■"); } else { System.out.print(" "); } } System.out.println(); } } } \\\\\\\\\\\ If you have any suggestions or suggestions on how to write more simply, please let me know.

Recommended Posts

[Question] Draw a diamond in a rectangle
Draw a too beloved Mandelbrot set in Processing
[Swift 5] Draw a line.
Multiplication in a Ruby array
Find a subset in Java
Draw a gradient with CAGradientLayer
[Java] Draw a simple pattern