Python
```python
import turtle
def draw_square(side_length):
for i in range(side_length):
for j in range(side_length):
print("*", end="")
print()
draw_square(5)
```
Python(使用turtle库)
```python
import turtle
def draw_square():
turtle.speed(1)
for _ in range(4):
turtle.forward(100)
turtle.right(90)
turtle.done()
draw_square()
```
Java
```java
import java.awt.*;
import javax.swing.*;
public class DrawSquare {
public static void main(String[] args) {
JFrame frame = new JFrame("画正方形");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400, 400);
JPanel panel = new JPanel() {
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
g.setColor(Color.RED);
g.fillRect(50, 50, 100, 100);
}
};
frame.add(panel);
frame.setVisible(true);
}
}
```
C
```csharp
using System;
using System.Drawing;
class Program {
static void Main() {
using (Graphics g = new Graphics()) {
g.Clear(Color.White);
g.DrawRectangle(Pens.Black, 50, 50, 100, 100);
}
}
}
```
JavaScript(使用HTML5 Canvas)
```html