今个学到String和数组了,布置了个双色球的习题
编码如下:
老司机来指教下有什么改进的(新手刚上路,有些专业名称还不大懂见谅啊~~~~)
public static void main(String args[]) {
System.out.println("双色球预测号:");
int i = 0;
String majia = "";
int num[] = new int[6];
while (i < 6) {
int rad = (int) (Math.random() * 33 + 1);
String rad2 = String.valueOf(rad);
String rad3 = rad2.concat(" ");
int index = majia.indexOf(rad3);
if (index == -1) {
majia = majia.concat(rad3);
num = rad;
i++;
}
}
int blue = (int) (Math.random() * 16 + 1);
System.out.println(num[0]+","+num[1]+","+num[2]+","+num[3]+","+num[4]+","+num[5]+" + "+blue);
System.out.println();
System.out.println("预祝你早日中大奖!");
}
|
|