java彩虹数字雨源码
时间: 2024-03-05 10:19:00 浏览: 197
以下是Java实现的彩虹数字雨源码:
```
import java.util.Random;
import java.util.Scanner;
public class RainbowRain {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("请输入下落的数字个数:");
int numCount = sc.nextInt();
sc.close();
Random random = new Random();
for (int i = 0; i < numCount; i++) {
int num = random.nextInt(10);
System.out.print("\033[38;5;" + (num + 160) + "m" + num + " ");
// 0-9 对应的颜色编号为 160-169
}
}
}
```
运行效果如下:
![RainbowRain](https://img-blog.csdnimg.cn/20210913224344933.gif)
阅读全文