سلام. من کد این مسئله رو با زبان جاوا نوشتم. سعی کردم تا حد امکان کد جمع و جور . ساده ای براش بنویسم.
* تذکر: برای ورودی گرفتن به ماژول util نیاز داشتم. اول اونو ایمپورت کردم و بعد بقیه کدمو نوشتم.
import java.util.Scanner;
public class codebezan1 {
public static void Squaremaking(){
System.out.println("Enter your number:");
Scanner userinput= new Scanner(System.in);
int x = userinput.nextInt();
for(int Lines=1 ; Lines< 2*x+2; Lines++){
System.out.print("\n");
for( int column=1 ; column< x+1 ; column++){
if(Lines%2 == 1){
System.out.print(" ---");
}
}
for(int column=1;column<x+2; column++){
if(Lines%2 == 0){
System.out.print("| ");
}
}
}
}
public static void main(String[] args){
Squaremaking();
}
}