数字彩虹雨java代码
时间: 2023-07-29 07:06:06 浏览: 205
以下是一个简单的数字彩虹雨 Java 代码:
```java
import java.util.Random;
public class RainbowNumbers {
public static void main(String[] args) throws InterruptedException {
Random random = new Random();
String[] colors = {"\u001B[31m", "\u001B[33m", "\u001B[32m", "\u001B[34m", "\u001B[35m", "\u001B[36m", "\u001B[37m"};
String[] numbers = {"0","1","2","3","4","5","6","7","8","9"};
while(true) {
for(int i = 0; i < 50; i++) {
String color = colors[random.nextInt(colors.length)];
String number = numbers[random.nextInt(numbers.length)];
System.out.print(color + number + " ");
}
System.out.println();
Thread.sleep(100);
}
}
}
```
这个程序会在控制台输出一连串的数字,每个数字都用随机的颜色进行渲染。程序会不停地运行,直到手动停止。
阅读全文