package test;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int num2 = scan.nextInt();
String square = "■";
//code
}
}
** Screenshots are all when the input value is 9. ** **
//Start at 1 and increment to the number entered
//* Line is the current number of lines and at the same time represents the number of drawings in ■.
for(int line = 1; line <= num2; line++ ){
//Start from 1 and repeat for less than or equal to the number of drawings on this line
for(int idxOfMarks = 1; idxOfMarks <= line; idxOfMarks++){
System.out.print(square);
}
//Line break to go to the next line
System.out.println("");
}
The following is a brief description.
StringBuilder sb = new StringBuilder();
for (int line = 0; line < num2; line++) {
System.out.println(sb.append(square));
}
//Start with the number you enter and decrement until that number reaches 1.
//* Idx is the current number of lines and at the same time represents the number of drawings in ■
for(int line = num2; line >= 1 ; line--){
for(int idxOfMarks = line; idxOfMarks >= 1; idxOfMarks--){
System.out.print(square);
}
System.out.println("");
}
String batsu = "×";
for(int line = 1; line <= num2; line++ ){
//Start from 1 and repeat for less than or equal to the number of drawings on this line
for(int idxOfMarks = 1; idxOfMarks <= line; idxOfMarks++){
if(idxOfMarks % 2 !=0){
System.out.print(square);
}else{
System.out.print(batsu);
}
}
System.out.println("");
}
for(int line = 1; line <= num2; line++){
for(int idxOfMarks = 1; idxOfMarks <= line; idxOfMarks++){
//If the row is odd
if(line % 2 != 0){
//When it becomes an odd number mark
if(idxOfMarks % 2 != 0){
System.out.print(square);
//When it becomes an even number mark
}else{
System.out.print(batsu);
}
//If the row is even
}else{
//When it becomes an odd number mark
if(idxOfMarks % 2 == 0){
System.out.print(square);
//When it becomes an even number mark
}else{
System.out.print(batsu);
}
}
}
System.out.println("");
}
for(int line = num2; line >=1; line--){
//The number of blanks displayed is the number of inputs-Ask in the current line
int empty = num2 - line;
//First, output the blank
for(int n=1 ;n <=empty; n++){
System.out.print(" ");
}
//Then print the mark
for(int idxOfMarks = line; idxOfMarks >= 1 ; idxOfMarks--){
System.out.print(square);
}
System.out.println("");
}
for(int line = 1 ; line<= num2 ; line++){
System.out.print(square);
}
System.out.println("");
int emptyLines = num2 - 2;
for(int line2 = 1; line2 <= emptyLines; line2++){
for (int index2 = 1 ; index2 <= num2; index2++){
if(index2 == 1 || index2 == num2){
System.out.print(square);
}else{
System.out.print(" ");
}
}
System.out.println("");
}
for(int line = 1 ; line<= num2 ; line++){
System.out.print(square);
}
for(int idx = 1; idx <= num2; idx++){
for(int i = 1; i <= num2-idx; i++){
System.out.print(" ");
}
for(int idxOfMarks = 1; idxOfMarks <= idx*2-1; idxOfMarks++){
System.out.print(square);
}
for(int i = 1; i <= num2-idx; i++){
System.out.print(" ");
}
System.out.println();
}
StringBuilder sb3 = new StringBuilder();
for (int line = 0; line < num2; line++) {
System.out.println(sb3.append(square));
}
for (int line = 0; line < num2; ++line){
System.out.println(sb3.deleteCharAt(0));
}
for(int line = 1 ; line <= num2; line++){
for(int idxOfNum=1; idxOfNum<=line; idxOfNum++){
if(line == 1 || line == 2 || line == num2){
System.out.print("●");
}else{
if(idxOfNum == 1 || idxOfNum == line){
System.out.print("●");
}else{
System.out.print("○");
}
}
}
System.out.println();
}
//When the number of lines increases by 1, the position of ● on the left becomes+1, the position of ● on the right is-It becomes 1.
int idxOfBlack1 = 1;
int idxOfBlack2 = num2;
for(int line = 1 ; line <= num2; line++){
for(int idxOfNum = 1; idxOfNum<=num2; idxOfNum++){
if(idxOfNum == idxOfBlack1 | idxOfNum == idxOfBlack2){
System.out.print("●");
}else{
System.out.print("○");
}
}
idxOfBlack1++;
idxOfBlack2--;
System.out.println();
}
(If you have a beautiful writing style, I would appreciate it if you could teach me.)
Recommended Posts