模拟双色球选号过程,使用java.util.Scanner类接收用户在控制台输入的5个红色球数字、2个蓝色球数字,并且在控制台输出用户选号结果:“您选择的号码是:红球:xx,xx,xx,xx,xx 蓝球:xx,xx。”
时间: 2024-03-10 15:46:36 浏览: 78
好的,我可以帮您写这段代码。请看以下代码:
```java
import java.util.Scanner;
public class DoubleColorBall {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int[] redBalls = new int[5];
int[] blueBalls = new int[2];
System.out.println("请输入您选的红球号码(1-33之间):");
for (int i = 0; i < redBalls.length; i++) {
redBalls[i] = scanner.nextInt();
}
System.out.println("请输入您选的蓝球号码(1-16之间):");
for (int i = 0; i < blueBalls.length; i++) {
blueBalls[i] = scanner.nextInt();
}
System.out.print("您选择的号码是:红球:");
for (int i = 0; i < redBalls.length; i++) {
System.out.print(redBalls[i]);
if (i != redBalls.length - 1) {
System.out.print(",");
}
}
System.out.print(" 蓝球:");
for (int i = 0; i < blueBalls.length; i++) {
System.out.print(blueBalls[i]);
if (i != blueBalls.length - 1) {
System.out.print(",");
}
}
}
}
```
运行程序后,您可以在控制台输入您选的号码,程序会将您选择的号码输出到控制台上。希望这个代码能够帮到您!
阅读全文