用Runnable接口方法进行多行程设计刚,线程功能为输出如下图形+*+**+***+****
时间: 2023-12-06 18:03:09 浏览: 121
实现Runnable接口创建多线程.docx
以下是使用Runnable接口方法进行多线程设计的代码,线程功能为输出如下图形:+、*、+*、**、+**、***、+***、****。
```java
class PrintThread implements Runnable {
private int n;
public PrintThread(int n) {
this.n = n;
}
public void run() {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++) {
if (j == 1 || j == i) {
System.out.print("+");
} else {
System.out.print("*");
}
}
System.out.println();
}
}
}
public class Main {
public static void main(String[] args) {
Thread t = new Thread(new PrintThread(4));
t.start();
}
}
```
阅读全文